0

What data is the parameter errorThrown (third parameter of jQuerys error callback function) Is it something, that the server (backend one has written, in my case it is some REST-based services written in Java) has to return, or is it something more general, which is "automatically" returned without one has to add some error-handling in ones code?

1
  • If the ajax call fails, an error is thrown, and a brief explanation of that error can be found in that argument. Commented Dec 31, 2013 at 15:55

3 Answers 3

2

Well, from jQuery.ajax()s documentation:

Type: Function( jqXHR jqXHR, String textStatus, String errorThrown ) ... When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error."...

So the errorThrown string coorseponds to the HTTP status response for any failure responses (>399) For a 400, it would be Bad Request, 500: Internal Server Error, etc...

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, yes.. this is what I thought. So somehow I do not get this error-data. Maybe I am doing something else wrong. Will have another look at it.
I too don't get useful information in this string either in the case of CORS difficulties or a bad url
0

Quote from the documentation:

error

Type: Function( jqXHR jqXHR, String textStatus, String errorThrown ) A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array of functions.

So basically the errorThrown parameter has nothing to do with the response sent from the server. It's just the error reason associated to the status code. If your server uses custom error reasons in addition to setting the status code, this parameter might be useful to retrieve it.

Comments

0

Something to note (I just ran into this) is that errorThrown will be an empty string for requests that were made with HTTP/2.

This is because the property comes from the statustext property of the underlying XHR, and that property does not get populated for HTTP/2 requests.

More info here: Why is the statusText of my XHR empty?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.