@gravitywelluk/error
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Gravitywell Error classes

Library to handle JSON API specification errors

CI License Downloads Version


Usage

Within your project you can specify the more project specific error codes, (see the example below)

import { ApiError } from "@gravitywelluk/error";

import APIError from "./ApiError";
import { ErrorType } from "./ApiError";

export enum ErrorCode {
  UserNotAllowed = "user_not_allowed",
}

export default class DecarbError extends APIError<ErrorCode> {}

Then you can use this class across your project for more consistant error handling:

throw new DecarbError(
  "User is not permitted to access that resource",
  ErrorType.Forbidden,
  ErrorCode.UserNotAllowed
);

Example error api response format

{
  "statusCode": 404,
  "body": {
    "error": {
      "message": "User not found",
      "type": "NOT_FOUND_ERROR"
    }
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @gravitywelluk/error

Weekly Downloads

27

Version

1.0.2

License

MIT

Unpacked Size

8.68 kB

Total Files

7

Last publish

Collaborators

  • gravitywell.uk