anyerr
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

anyerr

Get the message from any error of all shapes and sizes! Anyerr will traverse through deeply-nested error objects to find the error message.

import { parseAnyError } from '../src/index';
import axios from 'axios';

async function doSomething() {
  try {
    await axios.get('http://example.com');
  } catch (ex) {
    const { message } = parseAnyError(ex);
    console.error('Error while doing something:', message);
  }
}
Example error Output
{
  "ok": false,
  "data": {
    "error": {
      "code": 500,
      "message": {
        "detail": "Uh-oh, an oopsie-whoopsie has happened"
      }
    }
  }
}
Uh-oh, an oopsie-whoopsie has happened
{
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
  "title": "One or more validation errors occurred.",
  "status": 400,
  "traceId": "00-0b1f1c9a0a1b4f4e9f3b9b9b0a1b4f4e",
  "errors": {
    "name": [
      "The Name field is required."
    ]
  }
}
The Name field is required.

Readme

Keywords

none

Package Sidebar

Install

npm i anyerr

Weekly Downloads

0

Version

0.0.1

License

Apache-2.0

Unpacked Size

15.2 kB

Total Files

8

Last publish

Collaborators

  • hizkifw