Skip to content

applogik/axios-handle-error

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published