Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Dec 22, 2021
4 changes: 3 additions & 1 deletion lib/helpers/isAxiosError.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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);
});
});