I have this web application where the web services are hosted on Amazon API gateway & the client application is hosted on cloudefront site. The services are CORS enabled. For any error such as http 500, 401, 403 I am able to receive the http status from the jqxhr object using status
property. But it seem that for http status 413 i am getting status 0 in the code.
I have also noticed that http status 413 can be received if the request is made with in the server. But only for cross domain ajax, the status 413 is received as status 0.
Is there any way to handle http status 413 for cross domain ajax request.
Just brevity, consider the following code block, for http status 500, 401 the error callback log's out 500 or 401. But for 413 it displays 0.
$.ajax({
url: 'URL to AWS API Gateway',
success: function(d){
console.log(d);
},
error: function(a){
console.log( a.status );
}
});
See the following http://jsfiddle.net/tqgv7z9c/1/ (note http not https)
$.ajax({
url: 'http://www.mocky.io/v2/57bb03fc100000460a585000',
error: function(a){
$('#code').text( a.status );
}
});
I set it up using http://www.mocky.io/ with the following setup:
You can see the 413 code is correctly returned.
Without seeing more detail on the response you receive, I'd imagine the browser is taking a follow up action, I know this is a problem if a 304 Found
response comes back with a Location
header, this will cause a new request to occur and you won't be able to intercept before the browser continues. if this is what is happening for you, there is likely little you can do about it if you don't have the ability to modify the API itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With