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

fix($http) Indicate whether a request was aborted via status. #4491

Closed
jgrund opened this issue Oct 17, 2013 · 8 comments
Closed

fix($http) Indicate whether a request was aborted via status. #4491

jgrund opened this issue Oct 17, 2013 · 8 comments

Comments

@jgrund
Copy link
Contributor

jgrund commented Oct 17, 2013

Currently, there does not appear to be a way to determine whether a request was aborted or failed for another reason, as status is normalized to 0 in $http:

 /**
  * Resolves the raw $http promise.
  */
  function resolvePromise(response, status, headers) {
    // normalize internal statuses to 0
    status = Math.max(status, 0);

    (isSuccess(status) ? deferred.resolve : deferred.reject)({
      data: response,
      status: status,
      headers: headersGetter(headers),
      config: config
    });
  }

Internally a -1 is used to flag that the request either timed out or it was aborted via promise resolution.

What if we exposed the -1 as a valid status to give a better idea to rejection handlers why the request failed?

If this is the case I can create a PR to adress this issue.

@jbdeboer
Copy link
Contributor

+1, I like it. Send a PR!

@anton000
Copy link

+1
Anyone working on a PR for this? @jgrund @jbdeboer

status = (status >= -1)? status : 0; perhaps?

@btford btford removed the gh: issue label Aug 20, 2014
pkozlowski-opensource added a commit to pkozlowski-opensource/angular.js that referenced this issue Aug 24, 2014
pkozlowski-opensource added a commit to pkozlowski-opensource/angular.js that referenced this issue Aug 24, 2014
@yozo1984
Copy link

Can we do more than just propagate the status? A promise can be aborted via the timeout promise for any reason, it would be nice if the aborted reason is propagated as well.

Can we stringify the reject reason and propagated it through statusText?

@pkozlowski-opensource
Copy link
Member

@yozo1984 I'm not big fan of string-based APIs so I would prefer assign different status codes if we want to distinguish between timeout and promise-based aborting. We could obviously add proper status text, I'm just saying that that we should have proper status codes if we want to go down this path.

@yozo1984
Copy link

@pkozlowski-opensource How about put the aborted reason in the data field? Then it doesn't have to be string and can be live as blank like it is now.

@pkozlowski-opensource
Copy link
Member

@yozo1984 not sure I understand what you mean by data field... I don't think you've meant the same data object that holds data returned from the server, this would be bad idea, IMO.

Anyway, I don't think there is much problem with coming up with "artificial" abort statuses, ex. -1 for promise and -2 for timeout or something and adding informative status text on top.

@yozo1984
Copy link

@pkozlowski-opensource Sounds good. You are right. Second thoughts on the data field things and lots of problem comes out of it. Thank you for working on this.

@anton000
Copy link

@pkozlowski-opensource 👍

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

Successfully merging a pull request may close this issue.

6 participants