xero-ruby icon indicating copy to clipboard operation
xero-ruby copied to clipboard

Return more concise information with XeroRuby::ApiError

Open raouldevil opened this issue 4 years ago • 3 comments

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.

raouldevil avatar Jan 21 '21 07:01 raouldevil

cc: @mech - this work will be on the next release in case you have any other context you would like to add.

SerKnight avatar Jan 22 '21 18:01 SerKnight

I have nothing more to add if the errors API can be common and predictable across all different API 😀

mech avatar Jan 25 '21 02:01 mech

We're migrating from Xeroizer, and I think that their approach makes a lot of sense:

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.

ashkulz avatar Jan 25 '21 08:01 ashkulz