Skip to content

Commit

Permalink
Fixing possible runtime error in isAxiosError.js type guard
Browse files Browse the repository at this point in the history
AxiosError type guard can cause runtime error if payload is a `null`, since `null` also passes the check `typeof payload === 'object'`. Then the code cannot access `.isAxiosError` a `null`.

```
TypeError: Cannot read property 'isAxiosError' of null
```
  • Loading branch information
5argon committed Jan 31, 2021
1 parent 9a4d7ac commit 532a92d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/helpers/isAxiosError.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,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 (typeof payload === 'object') && (payload !== null) && (payload.isAxiosError === true);
};

0 comments on commit 532a92d

Please sign in to comment.