-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$http: allow differentiation between Request Error, Abort and Timeout #15626
Conversation
Adding param xhrStatus to response and separate handlers for onerror, onabort, ontimeout
Can you explain why you propose this change? |
This patch is in reference to issue #15380 regarding xhr requests being force timed out after 60 seconds on iOS 10. The issue is that in
which makes it difficult to differentiate between these possibilities in the callback. So separate handlers will help developers better handle these different errors by being able to show the respective error messages, etc. |
Sounds reasonable. I might actually need this myself in an app :) If we merge this, we also need to update the docs about this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need:
- More tests for the new feature (e.g. test for all possible values).
- Docs (as @Narretz mentioned already).
- Similar changes in the mocked
$httpBackend
inangular-mocks
.
} else { | ||
resolvePromise(cachedResp, 200, {}, 'OK'); | ||
resolvePromise(cachedResp, 200, {}, 'OK', 'Request Completed'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this strings just represent values (like an enum), not user messages, I think we should keep them as concise as possible. I propose:
- success
- error
- timeout
- abort
@@ -90,7 +90,7 @@ describe('$httpBackend', function() { | |||
}); | |||
|
|||
it('should call completion function with xhr.statusText if present', function() { | |||
callback.and.callFake(function(status, response, headers, statusText) { | |||
callback.and.callFake(function(status, response, headers, statusText, xhrStatus) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is redundant.
@@ -102,7 +102,7 @@ describe('$httpBackend', function() { | |||
}); | |||
|
|||
it('should call completion function with empty string if not present', function() { | |||
callback.and.callFake(function(status, response, headers, statusText) { | |||
callback.and.callFake(function(status, response, headers, statusText, xhrStatus) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is redundant.
@gkalpak can you please add more tests and documentation as required? |
I'll take a look to add more tests cases and update the docs. |
@frederikprijck Much appreciated! |
Continued in #15847 |
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Adding param xhrStatus to response and separate handlers for
onerror
,onabort
andontimeout
What is the current behavior? (You can also link to an open issue here)
Same handler for all error events
What is the new behavior (if this is a feature change)?
Separate handlers
Does this PR introduce a breaking change?
Probably not
Please check if the PR fulfills these requirements
Other information:
Some additional tests might be required in
httpSpec.js
and the docs would need updating as well.