mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +03:00
Adding isAxiosError typeguard documentation (#3767)
Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
committed by
GitHub
parent
0ece97c7a9
commit
94fc4ea716
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user