Page 1 of 1

Server code: send correct mime type for error with json body

Posted: Mon Nov 04, 2013 9:46 pm
by Vladimir Fesko

Hello!
Is it possible to to send correct mime type for errors in serve code?
I have to use XMLHttpRequest and forward its response to client. For error it returns good response code (like 404) and error body as JSON object:

var xhrResponse = XHR.send(..);
// xhrResponse.body is {"description":"User 'xxx' does not exist.","code":"DBUI110"}"
// xhrResponse.status is 404
response.error(xhrResponse .body, xhrResponse .status);

---

This produces response with code 404, specified body AND mime type /
Firefox says "not well formed" and doesn't work properly because it expects mime type to be "application/json" for this particular body.

How could I send correct mime type with error response? Or in general - a responce with specific body, code and headers?


Server code: send correct mime type for error with json body

Posted: Mon Nov 04, 2013 11:42 pm
by Alena Prykhodko

Hello Vladimir!

Sorry for late response, need time to check it. We'll get back to you as soon as possible.


Server code: send correct mime type for error with json body

Posted: Tue Nov 05, 2013 1:46 pm
by Maryna Brodina

Hello! Sorry for delay. All responses you can send from server code are described here http://docs.appery.io/documentation/b...
Content-Type:/ doesn't affect anything. Could yo clarify what are you trying to do and what exactly doesn't work?


Server code: send correct mime type for error with json body

Posted: Tue Nov 05, 2013 8:53 pm
by Vladimir Fesko

Actually, it was the case when I tried to test my app with Firefox and Selenium. In Firefox 24.0 and selenium ide 2.4.0 it didn't work for some reason. Maybe it wasn't direct reason but it's he thing you should mention. Your're right, it's not a big problem but a small lack of useful feature - is there any way to send desired content type with "response.error", not only with "response.success" and "response.binary" ?

Thank you!


Server code: send correct mime type for error with json body

Posted: Wed Nov 06, 2013 12:25 pm
by Maryna Brodina

Hello! [quote:]is there any way to send desired content type with "response.error"[/quote] No

not sure I understand when you receive error in Firefox. If you have 404 error in response result won't parse, or you parse it manually?