File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -826,10 +826,21 @@ axios depends on a native ES6 Promise implementation to be [supported](http://ca
826826If your environment doesn't support ES6 Promises, you can [ polyfill] ( https://github.com/jakearchibald/es6-promise ) .
827827
828828## TypeScript
829- axios includes [ TypeScript] ( http://typescriptlang.org ) definitions.
829+
830+ axios includes [ TypeScript] ( http://typescriptlang.org ) definitions and a type guard for axios errors.
831+
830832``` typescript
831- import axios from ' axios' ;
832- axios .get (' /user?ID=12345' );
833+ let user: User = null ;
834+ try {
835+ const { data } = await axios .get (' /user?ID=12345' );
836+ user = data .userDetails ;
837+ } catch (error ) {
838+ if (axios .isAxiosError (error )) {
839+ handleAxiosError (error );
840+ } else {
841+ handleUnexpectedError (error );
842+ }
843+ }
833844```
834845
835846## Online one-click setup
You can’t perform that action at this time.
0 commit comments