1.0.1 • Published 3 years ago

axios-error-handler v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

axios-error-handler

The utilities for error handling with axios.

npm version npm downloads

Features:

  • Define error handlers based on response status code
  • Wildcards mathching a class of status codes

Install

npm i axios-error-handler

Usage

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

sponsors

License

MIT © SevenOutman