Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Angular $http - handle differently xhr.onabort, xhr.ontimeout and xhr.onerror #15924

Closed
@jtassin

Description

@jtassin

I'm submitting a ...

  • bug report
  • feature request
  • other (Please do not submit support requests here (see above))

Current behavior:
$httpBackend handles xhr.onabort and xhr.ontimeout the same way than xhr.onerror.

It is a problem when using an error handler on $http(config). Typically, in my company, we resend http errors to our server and we currently can't exploit those errors to detect timeout or real http error (too much false positives from aborted requests). This is the object that the handler get :

{data: null, status: -1, config: Object, statusText: "", headers: function}

Expected / new behavior:
A very usefull result could be to that the handler get something like :

  • for abortion
    {data: null, status: -1, config: Object, statusText: "abort", headers: function}
  • for timeout
    {data: null, status: -1, config: Object, statusText: "timeout", headers: function}
  • for other errors
    {data: null, status: -1, config: Object, statusText: "", headers: function}

Minimal reproduction of the problem with instructions:

When I run this code :

$http({
  timeout: canceller.promise,
  method: 'GET',
  url : 'https://Idonotexist'
}).catch(vm.errorHandler);

I expect than vm.errorHandler can handle differently aborted errors than other errors.
But it always get

{data: null, status: -1, config: Object, statusText: "", headers: function}

For all three errors (error/timeout and abort)

Here is a jsfiddle to reproduce it easilly.

Angular version: 1.6.4

Browser: [all]

Anything else:
Here is the $httpBackend code :

var requestError = function() {
  // The response is always empty
 // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error
  completeRequest(callback, -1, null, null, '');
};

xhr.onerror = requestError;
xhr.onabort = requestError;
xhr.ontimeout = requestError;

It could be nice to change it to :

(

var requestError = function() {
) :

var requestError = function(statusText) {
  return function() {
    // The response is always empty
    // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error
    completeRequest(callback, -1, null, null, '');
  }
};

xhr.onerror = requestError('');
xhr.onabort = requestError('abort');
xhr.ontimeout = requestError('timeout');

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions