Reputation: 11
Is there a way to access to the content of the response of a 'core-ajax handleAs="document" request that receives a '4xx' http status code?
Upvotes: 0
Views: 693
Reputation: 3422
Add an error handler to your core-ajax element:
<core-ajax on-core-error="{{onError}}" ...>
Your callback function receives an event object, lets name it e
. e.detail.response
only contains an informative message string, but e.detail.xhr
contains the original XHR response object.
Edit: Additional note when using handleAs="document"
: In this case an exception is thrown when using Polymer 0.3.4.
Uncaught InvalidStateError: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'document').
This is the offending code
var response = xhr.status + ': ' + xhr.responseText;
So the error handling code doesn't check if the response type was set to document.
In this case you may need to use the core-xhr element directly.
Upvotes: 2