Skip to content

Commit

Permalink
refactor(helpers): optimize the logic of isAxiosError
Browse files Browse the repository at this point in the history
1. add the judgment of null
  • Loading branch information
BlackHole1 committed Jan 14, 2021
1 parent fe52a61 commit 11c1825
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/helpers/isAxiosError.js
@@ -1,11 +1,13 @@
'use strict';

var utils = require('./../utils');

/**
* Determines whether the payload is an error thrown by Axios
*
* @param {*} payload The value to test
* @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 changes: 5 additions & 0 deletions test/specs/helpers/isAxiosError.spec.js
Expand Up @@ -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);
});
});

0 comments on commit 11c1825

Please sign in to comment.