|Passing through response body on error.||Eric||9/10/12 11:42 AM|
Okay, so I'm wondering if it possible to get the body of the error. The reason is that sometimes my services return an exception with text I want to display to the user. This will be some kind of business rule validation that is best performed by the web server or the database layer of the application. Something like this.
When I look at the Amplify code, I can see on line 566 that it always passes NULL to the error handler function. For me what I'd like to get passed into the error handler is something like JSON.parse(_xhr.responseText). Another developer actually edited the amplify library to allow it to pass through the value here.
I was wondering if you guys had a more elegant idea. Perhaps we are "doing it wrong".
|Re: [amplifyjs] Passing through response body on error.||Scott González||9/10/12 11:49 AM|
There's nothing wrong with what you're doing. Unfortunately the web is mostly broken when it comes to error responses, so we don't handle this case in amplify. Decoders will allow you to perform any processing you want prior to the callbacks being invoked, so that would be the proper place to handle JSON decoding of an error message. Check out the built-in jsend decoder for an example of how to set one up: https://github.com/appendto/amplify/blob/afef2b7022146bb2ac61a6b2466b98176bcd9a87/request/amplify.request.js#L345
|Re: [amplifyjs] Passing through response body on error.||Eric||9/10/12 11:52 AM|
Thanks Scott I think the decoder is exactly what I'm looking for.