mirror of
https://github.com/tenrok/axios.git
synced 2026-05-21 13:24:11 +03:00
Merge pull request #205 from latentflip/fix-204
Fixing reject not being called on xhr network errors.
This commit is contained in:
@@ -63,6 +63,16 @@ module.exports = function xhrAdapter(resolve, reject, config) {
|
||||
request = null;
|
||||
};
|
||||
|
||||
// Handle low level network errors
|
||||
request.onerror = function handleError() {
|
||||
// Real errors are hidden from us by the browser
|
||||
// onerror should only fire if it's a network error
|
||||
reject(new Error('Network Error'));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
};
|
||||
|
||||
// Add xsrf header
|
||||
// This is only done if running in a standard browser environment.
|
||||
// Specifically not if we're in a web worker, or react-native.
|
||||
|
||||
@@ -54,6 +54,29 @@ describe('requests', function () {
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should reject on network errors', function (done) {
|
||||
// disable jasmine.Ajax since we're hitting a non-existant server anyway
|
||||
jasmine.Ajax.uninstall();
|
||||
|
||||
var resolveSpy = jasmine.createSpy('resolve');
|
||||
var rejectSpy = jasmine.createSpy('reject');
|
||||
|
||||
var finish = function () {
|
||||
expect(resolveSpy).not.toHaveBeenCalled();
|
||||
|
||||
expect(rejectSpy).toHaveBeenCalledWith(jasmine.any(Error));
|
||||
expect(rejectSpy.calls.argsFor(0)[0].message).toEqual('Network Error');
|
||||
|
||||
done();
|
||||
};
|
||||
|
||||
axios({
|
||||
url: 'http://thisisnotaserver'
|
||||
})
|
||||
.then(resolveSpy, rejectSpy)
|
||||
.then(finish, finish);
|
||||
});
|
||||
|
||||
it('should make cross domian http request', function (done) {
|
||||
var request, response;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user