Passing through response body on error.

591 views
Skip to first unread message

Eric

unread,
Sep 10, 2012, 2:42:25 PM9/10/12
to ampl...@googlegroups.com
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.

{
status:"fail",
message:"Delete conflicted with foriegn key constraint FK_XXXXXXXX."
}

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".






Scott González

unread,
Sep 10, 2012, 2:49:42 PM9/10/12
to ampl...@googlegroups.com
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

Eric

unread,
Sep 10, 2012, 2:52:16 PM9/10/12
to ampl...@googlegroups.com
Thanks Scott I think the decoder is exactly what I'm looking for.
Reply all
Reply to author
Forward
0 new messages