Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AJAX errors are sometimes ignored (httpErrorCallbackFn and remote-url-error-callback) #500

Open
rvalitov opened this issue Jul 2, 2017 · 0 comments

Comments

@rvalitov
Copy link

rvalitov commented Jul 2, 2017

According to the documentation remote-url-error-callback parameter defines a user function which is supposed to be called when AJAX error happens. However, this function is called only for cases when the server returns a error code (for example, 404 Not Found, or 500 Internal Server Error). But there are also other types of network errors, when the callback function is not fired, I tested the following cases (probably there are more):

  • Invalid domain name (the browser couldn't resolve the domain name = domain name not found)
  • HTTP timeout (the server didn't respond)
  • CORS error (the origin is not allowed by Access-Control-Allow-Origin)

The call to user defined callback function is ignored, because of the following code:

function httpErrorCallback(errorRes, status, headers, config) {
        scope.searching = httpCallInProgress;

        // normalize return obejct from promise
        if (!status && !headers && !config) {
          status = errorRes.status;
        }

        // cancelled/aborted
        if (status === 0 || status === -1) { return; }

It checks that error status code should not be 0 and -1. However, for all network errors (such as I mentioned above), when the HTTP status code couldn't be obtained from the server because the connection failed, the status will be -1.

It's not documented in AngularJS how to validate that the request was aborted/cancelled or it actually failed:

A response status code between 200 and 299 is considered a success status and will result in the success callback being called. Any response status code outside of that range is considered an error status and will result in the error callback being called. Also, status codes less than -1 are normalized to zero. -1 usually means the request was aborted, e.g. using a config.timeout

For example, in jQuery such situation is well documented:

Possible values for the textStatus 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."

I think that the user callback function should be called in any case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant