Skip to main content

@rtorcato/api-errors v1.0.0

Classes​

HttpError​

Defined in: index.ts:1

Extends​

  • Error

Extended by​

Constructors​

Constructor​

new HttpError(status, message, code?): HttpError

Defined in: index.ts:5

Parameters​
status​

number

message​

string

code?​

string = 'http_error'

Returns​

HttpError

Overrides​

Error.constructor

Properties​

status​

readonly status: number

Defined in: index.ts:2

code​

readonly code: 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​

BadRequestError

Overrides​

HttpError.constructor

Properties​

status​

readonly status: number

Defined in: index.ts:2

Inherited from​

HttpError.status

code​

readonly code: string

Defined in: index.ts:3

Inherited from​

HttpError.code


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​

UnauthorizedError

Overrides​

HttpError.constructor

Properties​

status​

readonly status: number

Defined in: index.ts:2

Inherited from​

HttpError.status

code​

readonly code: string

Defined in: index.ts:3

Inherited from​

HttpError.code


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​

ForbiddenError

Overrides​

HttpError.constructor

Properties​

status​

readonly status: number

Defined in: index.ts:2

Inherited from​

HttpError.status

code​

readonly code: string

Defined in: index.ts:3

Inherited from​

HttpError.code


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​

NotFoundError

Overrides​

HttpError.constructor

Properties​

status​

readonly status: number

Defined in: index.ts:2

Inherited from​

HttpError.status

code​

readonly code: string

Defined in: index.ts:3

Inherited from​

HttpError.code


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​

ConflictError

Overrides​

HttpError.constructor

Properties​

status​

readonly status: number

Defined in: index.ts:2

Inherited from​

HttpError.status

code​

readonly code: string

Defined in: index.ts:3

Inherited from​

HttpError.code


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​

UnprocessableEntityError

Overrides​

HttpError.constructor

Properties​

status​

readonly status: number

Defined in: index.ts:2

Inherited from​

HttpError.status

code​

readonly code: string

Defined in: index.ts:3

Inherited from​

HttpError.code


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​

TooManyRequestsError

Overrides​

HttpError.constructor

Properties​

status​

readonly status: number

Defined in: index.ts:2

Inherited from​

HttpError.status

code​

readonly code: string

Defined in: index.ts:3

Inherited from​

HttpError.code


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​

InternalServerError

Overrides​

HttpError.constructor

Properties​

status​

readonly status: number

Defined in: index.ts:2

Inherited from​

HttpError.status

code​

readonly code: string

Defined in: index.ts:3

Inherited from​

HttpError.code


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​

ServiceUnavailableError

Overrides​

HttpError.constructor

Properties​

status​

readonly status: number

Defined in: index.ts:2

Inherited from​

HttpError.status

code​

readonly code: string

Defined in: index.ts:3

Inherited from​

HttpError.code

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?​

optional stack?: 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

Returns​

ErrorResponse