提交 252876c2 编写于 作者: P Philip Roberts

Fixing reject not being called on xhr network errors.

Fixes #204
上级 a473744e
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册