This module exposes a series of predefined errors to be used consistently across all the iCapps API's.
yarn add guinan-api-errors
const ApiError = require('guinan-api-errors')
Configure once at the entry point of your app: ApiError.config({})
.
You can pass a config object which will extend the default iCapps error definitions. Make sure to use error codes > 9999 for additional error definitions.
Use the format:
{
10010: {
message: "Parking is full",
url: "http://example.com/errors/10010",
},
}
ApiError
exposes the methods badRequest, forbidden, unauthorized, notFound, serviceUnavailable and internalServer
. They all take the arguments (code: Number, detail: String)
.
E.g: throw ApiError.badRequest(1001, "Something went wrong")
.
BadRequestError
,NotFoundError
,ForbiddenError
,UnauthorizedError
,ServiceUnavailableError
,InternalServerError
,
All errors are also instances of Error
, ApiError
.
Clone the repo and install dependencies: yarn
.
Run the tests with yarn test
.