2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-14 18:42:33 +03:00

Fixing getting local files (file://) failed (#2470)

* fix issue #2416, #2396

* fix Eslint warn

* Modify judgment conditions

* add unit test

* update unit test

* update unit test
This commit is contained in:
Alan Wang
2020-03-23 21:49:38 +08:00
committed by GitHub
parent 5189afff38
commit 885ada6d9b
2 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ var createError = require('./createError');
*/
module.exports = function settle(resolve, reject, response) {
var validateStatus = response.config.validateStatus;
if (!validateStatus || validateStatus(response.status)) {
if (!response.status || !validateStatus || validateStatus(response.status)) {
resolve(response);
} else {
reject(createError(
+20
View File
@@ -157,6 +157,26 @@ describe('requests', function () {
});
});
it('should resolve when the response status is 0 (i.e. requesting with file protocol)', function (done) {
var resolveSpy = jasmine.createSpy('resolve');
var rejectSpy = jasmine.createSpy('reject');
axios('file:///xxx').then(resolveSpy)
.catch(rejectSpy)
.then(function () {
expect(resolveSpy).toHaveBeenCalled();
expect(rejectSpy).not.toHaveBeenCalled();
done();
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 0,
responseURL: 'file:///xxx',
});
});
});
// https://github.com/axios/axios/issues/378
it('should return JSON when rejecting', function (done) {
var response;