diff --git a/README.md b/README.md index 5def9d52b2..a013b2b9a7 100755 --- a/README.md +++ b/README.md @@ -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