@rtorcato/api-errors v1.0.0
Classes
HttpError
Defined in: index.ts:1
Extends
Error
Extended by
BadRequestErrorUnauthorizedErrorForbiddenErrorNotFoundErrorConflictErrorUnprocessableEntityErrorTooManyRequestsErrorInternalServerErrorServiceUnavailableError
Constructors
Constructor
new HttpError(
status,message,code?):HttpError
Defined in: index.ts:5
Parameters
status
number
message
string
code?
string = 'http_error'
Returns
Overrides
Error.constructor
Properties
status
readonlystatus:number
Defined in: index.ts:2
code
readonlycode:string
Defined in: index.ts:3
BadRequestError
Defined in: index.ts:13
Extends
Constructors
Constructor
new BadRequestError(
message?,code?):BadRequestError
Defined in: index.ts:14
Parameters
message?
string = 'Bad Request'
code?
string = 'bad_request'
Returns
Overrides
Properties
status
readonlystatus:number
Defined in: index.ts:2
Inherited from
code
readonlycode:string
Defined in: index.ts:3
Inherited from
UnauthorizedError
Defined in: index.ts:20
Extends
Constructors
Constructor
new UnauthorizedError(
message?,code?):UnauthorizedError
Defined in: index.ts:21
Parameters
message?
string = 'Unauthorized'
code?
string = 'unauthorized'
Returns
Overrides
Properties
status
readonlystatus:number
Defined in: index.ts:2
Inherited from
code
readonlycode:string
Defined in: index.ts:3
Inherited from
ForbiddenError
Defined in: index.ts:27
Extends
Constructors
Constructor
new ForbiddenError(
message?,code?):ForbiddenError
Defined in: index.ts:28
Parameters
message?
string = 'Forbidden'
code?
string = 'forbidden'
Returns
Overrides
Properties
status
readonlystatus:number
Defined in: index.ts:2
Inherited from
code
readonlycode:string
Defined in: index.ts:3
Inherited from
NotFoundError
Defined in: index.ts:34
Extends
Constructors
Constructor
new NotFoundError(
message?,code?):NotFoundError
Defined in: index.ts:35
Parameters
message?
string = 'Not Found'
code?
string = 'not_found'
Returns
Overrides
Properties
status
readonlystatus:number
Defined in: index.ts:2
Inherited from
code
readonlycode:string
Defined in: index.ts:3
Inherited from
ConflictError
Defined in: index.ts:41
Extends
Constructors
Constructor
new ConflictError(
message?,code?):ConflictError
Defined in: index.ts:42
Parameters
message?
string = 'Conflict'
code?
string = 'conflict'
Returns
Overrides
Properties
status
readonlystatus:number
Defined in: index.ts:2
Inherited from
code
readonlycode:string
Defined in: index.ts:3
Inherited from
UnprocessableEntityError
Defined in: index.ts:48
Extends
Constructors
Constructor
new UnprocessableEntityError(
message?,code?):UnprocessableEntityError
Defined in: index.ts:49
Parameters
message?
string = 'Unprocessable Entity'
code?
string = 'unprocessable_entity'
Returns
Overrides
Properties
status
readonlystatus:number
Defined in: index.ts:2
Inherited from
code
readonlycode:string
Defined in: index.ts:3
Inherited from
TooManyRequestsError
Defined in: index.ts:55
Extends
Constructors
Constructor
new TooManyRequestsError(
message?,code?):TooManyRequestsError
Defined in: index.ts:56
Parameters
message?
string = 'Too Many Requests'
code?
string = 'too_many_requests'
Returns
Overrides
Properties
status
readonlystatus:number
Defined in: index.ts:2
Inherited from
code
readonlycode:string
Defined in: index.ts:3
Inherited from
InternalServerError
Defined in: index.ts:62
Extends
Constructors
Constructor
new InternalServerError(
message?,code?):InternalServerError
Defined in: index.ts:63
Parameters
message?
string = 'Internal Server Error'
code?
string = 'internal_server_error'
Returns
Overrides
Properties
status
readonlystatus:number
Defined in: index.ts:2
Inherited from
code
readonlycode:string
Defined in: index.ts:3
Inherited from
ServiceUnavailableError
Defined in: index.ts:69
Extends
Constructors
Constructor
new ServiceUnavailableError(
message?,code?):ServiceUnavailableError
Defined in: index.ts:70
Parameters
message?
string = 'Service Unavailable'
code?
string = 'service_unavailable'
Returns
Overrides
Properties
status
readonlystatus:number
Defined in: index.ts:2
Inherited from
code
readonlycode:string
Defined in: index.ts:3
Inherited from
Interfaces
ErrorResponse
Defined in: index.ts:77
The standard JSON error body sent by the framework error handlers.
Properties
error
error:
string
Defined in: index.ts:78
code
code:
string
Defined in: index.ts:79
message
message:
string
Defined in: index.ts:80
stack?
optionalstack?:string
Defined in: index.ts:81
Functions
toErrorResponse()
toErrorResponse(
err,options?):ErrorResponse
Defined in: index.ts:96
Serialize any thrown value into the standard error envelope
{ error, code, message, stack? }. HttpError instances surface their
code; anything else becomes internal_server_error.
The HTTP status is not part of the body — read it from err.status on an
HttpError separately.
Single source of truth for the error body: the Express/Hono error handlers and any middleware that responds with an error (e.g. rate limiting) build their JSON from here, so the shape can't drift between them.
Parameters
err
unknown
options?
includeStack?
boolean