File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed 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
826
826
If your environment doesn't support ES6 Promises, you can [ polyfill] ( https://github.com/jakearchibald/es6-promise ) .
827
827
828
828
## 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
+
830
832
``` 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
+ }
833
844
```
834
845
835
846
## Online one-click setup
You can’t perform that action at this time.
0 commit comments