https://github.com/sevenoutman/axios-error-handler
https://github.com/sevenoutman/axios-error-handler
axios
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/sevenoutman/axios-error-handler
- Owner: SevenOutman
- License: mit
- Created: 2022-03-06T13:57:51.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-25T10:01:30.000Z (about 4 years ago)
- Last Synced: 2025-01-08T11:23:47.088Z (over 1 year ago)
- Topics: axios
- Language: TypeScript
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# axios-error-handler
The utilities for error handling with axios.
[](https://npm.im/axios-error-handler) [](https://npm.im/axios-error-handler)
## Features:
- Define error handlers based on response status code
- Wildcards mathching a class of status codes
## Install
```bash
npm i axios-error-handler
```
## Usage
```ts
import { createErrorHandler } from "axios-error-handler"
axios.interceptors.response.use(
null,
createErrorHandler({
// Runs this callback if thrown.response.status is 401
401(thrown) {
alert("")
},
// Runs this callback if thrown.response.status is 5xx
"5xx"(thrown) {
alert("")
},
}),
)
```
## Sponsors
[](https://github.com/sponsors/SevenOutman)
## License
MIT © [SevenOutman](https://github.com/sponsors/SevenOutman)