2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-30 15:24:11 +03:00

refactor(helpers): optimize the logic of isAxiosError (#3546)

1. add the judgment of null

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Black-Hole
2021-12-23 03:09:33 +08:00
committed by GitHub
parent 476ee88442
commit 6fca6a7027
2 changed files with 8 additions and 1 deletions
+3 -1
View File
@@ -1,5 +1,7 @@
'use strict';
var utils = require('./../utils');
/**
* Determines whether the payload is an error thrown by Axios
*
@@ -7,5 +9,5 @@
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
*/
module.exports = function isAxiosError(payload) {
return (typeof payload === 'object') && (payload.isAxiosError === true);
return utils.isObject(payload) && (payload.isAxiosError === true);
};
+5
View File
@@ -17,4 +17,9 @@ describe('helpers::isAxiosError', function () {
expect(isAxiosError(new Error('Boom!')))
.toBe(false);
});
it('should return false if the error is null', function () {
expect(isAxiosError(null))
.toBe(false);
});
});