XeroAPI / Xero-NetStandard

A wrapper of the Xero API in the .NetStandard 2.0 framework. Supports Accounting, Payroll AU/US, and Files
MIT License
120 stars 119 forks source link

Error messages returned from an API call missing #438

Closed mfonnesbeck closed 1 year ago

mfonnesbeck commented 1 year ago

We are using Xero.Api.SDK.Minimal v 2.2.9, Xero.NetStandard.OAuth2 v 3.1.0, and Xero.NetStandard.OAuth2Client v 0.0.5.

We have noticed that the errors being reported by Xero API calls have been simple and have not included details regarding what happened. We also have noticed that Rate Limit exceptions, that we used to get and coded to handle, have stopped happening.

A particular error we received this morning while making a call to GetReportAgedReceivablesByContact through the Xero API for C#.Net at 01 Sep 2022 09:31:37.456 MST or UTC timestamp 2022-09-01T15:31:36.9420191+00:00, for Customer account # Q07 in this organization, returned the following non-descript and unhelpful error:

Xero API error calling GetReportAgedReceivablesByContact:

There were several calls made to the same endpoint immediately following this call for other customers within the same organization, all returned the same simple and ineffective error message. We either get only "Xero API error calling ..." or "One or more errors occurred" with no details as to what the error was. When I asked Xero Customer Support for help to aid us in understanding why this call failed and what has happened to cause this error and similar errors to lose their details.

They responded with "I had a look at the timestamp you mentioned and the response headers sent from Xero were as below":

ResponseHeaders: { "Date": "Thu, 01 Sep 2022 15:31:56 GMT", "Server": "Kestrel", "Retry-After": "47", "Transfer-Encoding": "chunked", "Xero-Correlation-Id": "2b657b01-003c-428d-85a6-726b82cfe9ee", "X-AppMinLimit-Remaining": "9489", "X-MinLimit-Remaining": "0", "X-DayLimit-Remaining": "4721", "X-Rate-Limit-Problem": "minute" }

The problem is that we are using your C#.Net API and do not receive those headers and information in the details of the exception or response that comes back from your API. Are the newer versions of the API that we should be using to obtain these headers and messages to give us the details to know that it was a Rate Limit exception? We have code to look for and add pauses to our application, but we are not receiving this information to know that this exception has occurred. Xero Customer Support advised that we post an issue here. Please advise.

Thank you.

Abhisha1 commented 1 year ago

Hi @mfonnesbeck Thanks for getting in touch with us. I've had a look at what the behaviour is on the latest version of the SDK within our sample app that you can find here.

In the current version of the SDK, when rate limited a further call to the API raises an APIException with the message "Xero API minute rate limit error calling (xyz)". Is this what you are looking for? image

mfonnesbeck commented 1 year ago

Something like that yes. We used to get an exception raised Xero.Api.Infrastructure.Exceptions.RateExceededException, and we added catch blocks to capture this exception and then add a wait pause to our application to account for this. But the recent messages have not been coming back with this message, and frankly any message. We usually see a simple Exception the message "One or more errors occurred" and nothing else to let us know what happened. In bringing this up with Xero Support about a recent exception, they saw the Rate Limit message in the Response HTTP headers, but we never receive this information. That is why I was asked to bring this to your team.

Abhisha1 commented 1 year ago

Thanks @mfonnesbeck

For further information, I have shown what the entire Exception object returned is below with the debugger. With the latest version of the SDK, the exception is thrown with the ErrorCode reported as 429 (HTTP status code for too many requests and being rate limited) along with the Message indicating there is a rate limiting error. This can be used to capture such errors.

image

Unless you had any other questions, can I mark this issue as resolved?

mfonnesbeck commented 1 year ago

Ok. So what you are stating is that we need to upgrade our SDK version? We are using Xero.Api.SDK.Minimal v 2.2.9, Xero.NetStandard.OAuth2 v 3.1.0, and Xero.NetStandard.OAuth2Client v 0.0.5.

The question is, why is this not backward compatible and why did it just stop working in the version of the SDK that we are using? Answer these questions and we can close this issue.

Thank you.

Merrick

Abhisha1 commented 1 year ago

Hi @mfonnesbeck Apologies for the delay!

The current version for Xero.NetStandard.OAuth2 is 3.28.0, Xero.NetStandard.OAuth2Client 1.6.0 and Xero.Api.SDK.Minimal is now deprecated. The versions you are currently using are outdated so please upgrade to the current versions to ensure you have the latest changes. Unfortunately we do not have backward compatibility due to resource constraints within the team.

I have had a look at the versions you were using and the SDK itself hasn't been updated since 2020. Most likely, there may have been a change at the API level that changed the way the rate limiting was handled. However, the latest version of the SDL will throw an API exception with the rate limiting message which allows you to capture and handle this appropriately.

Hope that helps

mfonnesbeck commented 1 year ago

Thank you for your response and information. We will take your advice into consideration and look to upgrading promptly.

Thanks.