Skip to content

Commit

Permalink
Adding isAxiosError typeguard documentation (#3767)
Browse files Browse the repository at this point in the history
Co-authored-by: Jay <jasonsaayman@gmail.com>
  • Loading branch information
johachi and jasonsaayman committed May 4, 2021
1 parent 0ece97c commit 94fc4ea
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions README.md
Expand Up @@ -826,10 +826,21 @@ axios depends on a native ES6 Promise implementation to be [supported](http://ca
If your environment doesn't support ES6 Promises, you can [polyfill](https://github.com/jakearchibald/es6-promise).

## TypeScript
axios includes [TypeScript](http://typescriptlang.org) definitions.

axios includes [TypeScript](http://typescriptlang.org) definitions and a type guard for axios errors.

```typescript
import axios from 'axios';
axios.get('/user?ID=12345');
let user: User = null;
try {
const { data } = await axios.get('/user?ID=12345');
user = data.userDetails;
} catch (error) {
if (axios.isAxiosError(error)) {
handleAxiosError(error);
} else {
handleUnexpectedError(error);
}
}
```

## Online one-click setup
Expand Down

0 comments on commit 94fc4ea

Please sign in to comment.