http-request error response bodies in Saxon-JS 1.2.0
Added by David Cramer over 5 years ago
When I use ixsl:schedule-action to do an http-request, I'm not getting a body in the response map for errors (though the bodies do show up just fine for 2xx responses). For example, POSTing a malformed document, I'm returned:
map{"headers":map{"connection":"close", "content-type":"application/xml;charset=UTF-8", "transfer-encoding":"Identity", "date":"Wed, 20 Mar 2019 00:16:19 GMT"}, "status":400, "message":"", "type":"load"}
If I submit the same malformed request via Postman, I get the following response:
Content-Type →application/xml;charset=UTF-8 Transfer-Encoding →chunked Date →Tue, 19 Mar 2019 20:11:49 GMT Connection →close
Body:
One validation error was reported: In content of element <document>: element <title> is not presentAny suggestions on what it takes to get the response body from errors?
Regards, David
Replies (7)
Please register to reply
RE: http-request error response bodies in Saxon-JS 1.2.0 - Added by David Cramer over 5 years ago
I guess the markup in my message was rendered by the browser. Let me try it again with some wiki markup:
Body:
<error code="400" xmlns="http://www.apple.com/hwtdocs/common">
<message>One validation error was reported: In content of element <document>: element <title> is not present</message>
<details>
Request URI : /docs/
</details>
</error>
RE: http-request error response bodies in Saxon-JS 1.2.0 - Added by Debbie Lockett over 5 years ago
This looks like a bug: I've raised it here Bug #4174: No response body from HTTP request when http.status >= 400
Having looked in the Saxon-JS code (BrowserPlatform makeHttpRequest) it appears that we only add response.body
in the response map if !request["status-only"] && http.status < 400
. i.e. if the HTTP response status code is less than 400. I'm not sure where that restriction came from; I probably wrongly assumed that error responses never have bodies...
RE: http-request error response bodies in Saxon-JS 1.2.0 - Added by David Cramer over 5 years ago
Thanks Debbie. I can confirm that deleting " && http.status < 400" from that line in SaxonJS.js gives me the error bodies.
RE: http-request error response bodies in Saxon-JS 1.2.0 - Added by Debbie Lockett over 5 years ago
Excellent, glad to hear that gives you a work around, until we get a fix in a new release!
RE: http-request error response bodies in Saxon-JS 1.2.0 - Added by David Cramer over 5 years ago
While you're adding that fix, a few lines below that at line 373:
var part2 = typeParts[1].trim(); // will this work if 'Content-Type' string only contains media type?
In some situations, I get a JavaScript error from the browser: "undefined is not an object (evaluating 'typeParts[1].trim')". However the variable doesn't seem to be used, so I've commented out the line.
Regards, David
RE: http-request error response bodies in Saxon-JS 1.2.0 - Added by David Cramer over 5 years ago
One other thing I was puzzled by: When I do a HEAD request, Saxon-JS fails on line 454 with "XError: Misplaced or malformed XML". After walking through the JavaScript, I learned that if I added "status-only": true() to the request, I could avoid this issue, but it seems odd that I have to explicitly say I don't want a body when I'm already doing a HEAD request.
RE: http-request error response bodies in Saxon-JS 1.2.0 - Added by Debbie Lockett over 5 years ago
Thanks also for these additional comments. I will indeed look into making the appropriate changes to resolve these issues too! And do let us know if you come across anything else odd.
Please register to reply