1.0.2 • Published 3 years ago

@gravitywelluk/error v1.0.2

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

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"
    }
  }
}