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:
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user