axios-handle-error
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

axios-handle-error

Handles axios errors in a convenient way

Installation

Install using npm:

npm install --save axios-handle-error

Install using yarn:

yarn add axios-handle-error

Usage Example

import axios from "axios";
import handleAxiosError from "axios-handle-error";

axios
  .get('/your-api-call')
  .then((response) => response.data)
  .catch((e) => {
    throw handleAxiosError(e, {
      404: () => {
        return new Error('Element could not be found.');
      },
      '*': () => {
        return new Error('Unknown error occured.');
      },
      NO_RESPONSE: () => {
        return new Error('Server is not responding. Please try again.');
      },
    });
  });

Built With

  • Typescript - TypeScript is a typed superset of JavaScript that compiles to plain JavaScript

License

This project is licensed under the MIT License - see the LICENSE file for details.

Readme

Keywords

none

Package Sidebar

Install

npm i axios-handle-error

Weekly Downloads

45

Version

2.0.2

License

MIT

Unpacked Size

8.08 kB

Total Files

8

Last publish

Collaborators

  • ochrstn