> Base error class for better error handling
npm install @gravitywelluk/errorLibrary to handle JSON API specification errors
Within your project you can specify the more project specific error codes, (see the example below)
``typescript
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
`
Then you can use this class across your project for more consistant error handling:
`typescript`
throw new DecarbError(
"User is not permitted to access that resource",
ErrorType.Forbidden,
ErrorCode.UserNotAllowed
);
`json``
{
"statusCode": 404,
"body": {
"error": {
"message": "User not found",
"type": "NOT_FOUND_ERROR"
}
}
}