xero-ruby
xero-ruby copied to clipboard
Return more concise information with XeroRuby::ApiError
Currently when XeroRuby::ApiError is generated the error message returns a combination of guidance text, response headers and response body as a long text string. For a developer this is great, but there isn't really any easy way to use this information if we try to rescue XeroRuby::ApiError in our apps in a begin..rescue...end block. Also, in some cases when one of our users posts a bill with a lot of invoice lines, the error message seems to include the request information too, with all the submitted lines. This means the message gets truncated in our exception handling app, as it is too long and we are then not being able to see the actual error. It would be great if this could be a little more concise and structured, as we might want to show messages to users in some cases. For example, currently we see something like:
Error message: the server returns an error
HTTP status code: 403
Response headers: {"content-type"=>"application/json", "content-length"=>"150", "server"=>"nginx", "xero-correlation-id"=>"d54b3dd1-2fad-4de4-a4c6-bff86a96bae7", "x-appminlimit-remaining"=>"9999", "expires"=>"Wed, 13 Jan 2021 11:51:32 GMT", "cache-control"=>"max-age=0, no-cache, no-store", "pragma"=>"no-cache", "date"=>"Wed, 13 Jan 2021 11:51:32 GMT", "connection"=>"close", "x-client-tls-ver"=>"tls1.2"}
Response body: {"Type":null,"Title":"Forbidden","Status":403,"Detail":"AuthenticationUnsuccessful","Instance":"d54b3dd1-2fad-4de4-a4c6-bff86a96bae7","Extensions":{}}
Maybe this could be something like:
Error: Server Error, HTTP Status Code: 403, Reason: Authentication Unsuccessful.
Then we would extract info during a rescue clause.
cc: @mech - this work will be on the next release in case you have any other context you would like to add.
I have nothing more to add if the errors API can be common and predictable across all different API 😀
We're migrating from Xeroizer, and I think that their approach makes a lot of sense:
- Connection-level errors (e.g. timeout) are raised as-is e.g.
Net::OpenTimeout - OAuth level errors are also raised separately e.g.
Xeroizer::OAuth::RateLimitExceeded=> very useful to catch - Specific exception classes for errors
Right now, this library has everything in one error which makes error handling very difficult. I can understand not separating out the last part, but the first 2 types of errors should absolutely be separated out.