@gravitywelluk/error
v1.0.2
Published
> Base error class for better error handling
Downloads
99
Readme
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"
}
}
}