Rate limit header [retry-after] header missing in the latest purecloud-platform-client-v2 version

Hello Team,

We noticed that during our tests the latest version of purecloud-platform-client-v2 in the npm package is missing the retry-after headers.

For example, When we use the version 135.0.0 We get the error response as follows,

{
"status": 429,
"response": {
"req": {
"method": "GET",
"url": "https://api.mypurecloud.ie/api/v2/conversations/02c5bb5a-8103-4ce2-8386-8275750a1fb0",
"headers": {
"authorization": "Bearer HANDLE-AUTH-TOKENS-LIKE-PASSWORDS",
"content-type": "application/json",
"accept": "application/json"
}
},
"header": {
"content-type": "application/json",
"content-length": "208",
"connection": "close",
"date": "Mon, 15 May 2023 07:46:26 GMT",
"retry-after": "23",
"inin-correlation-id": "5dc1f74e-370e-424d-8445-738843183841",
"strict-transport-security": "max-age=600; includeSubDomains",
"cache-control": "no-cache, no-store, must-revalidate",
"x-cache": "Error from cloudfront",
"via": "1.1 4123f5d267403eba4e7db5e4d8d9a6e0.cloudfront.net (CloudFront)",
"x-amz-cf-pop": "CDG50-C2",
"x-amz-cf-id": "3jrxifvvHGRt4u7Dm8SveDFk8OzuYuHFc85vQeDXrLAKFw9rs3ryGg=="
},
"status": 429,
"text": "{"message":"Rate limit exceeded the maximum. Retry the request in [23] seconds","code":"too.many.requests.retry.after","status":429,"contextId":"5dc1f74e-370e-424d-8445-738843183841","details":[],"errors":[]}"
}
}

But from the version 137.1.0 the error response is changed and the below error response is for the version 167.0.0,

{
"message": "Rate limit exceeded the maximum. Retry the request in [14] seconds",
"code": "too.many.requests.retry.after",
"status": 429,
"contextId": "aa7a1cc9-f020-4a39-a130-5fd082f7cf2e",
"details": [],
"errors": []
}

We have the code and status displayed but the retry after headers with the value is not found to proceed further. Could you please let us know the reason for this response change? Is there any workaround for getting the headers? Thank you in advance!

Best Regards,
Punitha

Hi Punitha,

I have asked one of the devs to investigate this and see if we can reproduce it. Thanks for letting us know.

Thanks,
John Carnell

Hi Punitha,

The javascript SDK will only return the response body by default. To get the full response including headers you will need to add the following line to your code.

client.setReturnExtendedResponses(true)

Note: You accidentally included you access token in your original post. My colleague was able to remove it but in the future you should treat your access token like a password and not post it online. You should also consider generating a new access token as they were visible for quite a while.

Regards,
Declan

Hello Declan,

Thank you for your quick reply. I apologize for not removing the access token. I will make sure it will not happen again in the future.

The documentation(README.md) of MyPureCloud/platform-client-sdk-javascript states that error responses will always thrown as an extended response object.

I did some basic tests and it works as explained. So when we get the 429 error code it should throw as an extended response by default without specifying explicitly. Please correct me if I am wrong.

Because the earlier version(135.0.0) which I mentioned throws an extended error response from which we calculate the waiting time from the headers whereas in the latest versions we receive only the response body.

If we include the client.setReturnExtendedResponses(true) we are able to get the headers for 429. Since it will give us the full response we will have to do the code changes as it was implemented in the client side.

Could you please confirm whether we should explicitly set(setReturnExtendedResponses(true)) to get the extended error response for the status 429? Is it specific to only particular Api's? Can you please clarify on this?

Thank you in advance!

Hi Punitha,

You are right the javascript documentation does say that error responses will throw an extended response object, unfortunately this is a mistake in the README. This behaviour was changed and the documentation was never updated.

When using the latest sdk versions you will need to set returnExtended = true like I mentioned in my previous post to get an extended response for both successful operations and errors.

I apologies about the inconvenience and the documentation will be corrected in future versions.

Regards,
Declan

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.