Classes · @purista/core

HandledError

A handled error is an error which is handled or thrown by business logic. It is wanted to expose it the outside world. Scenarios are input validation failures or "404 Not Found" errors which should be returned to the caller.

Signature

HandledError.ts typescript
class HandledError

Constructors

1 entry

constructor

Constructor

Source
constructor.ts typescript
new constructor(errorCode: StatusCode, message?: string, data?: unknown, traceId?: string)

Properties

3 entries

data

Property

Source
data.ts typescript
data: unknown

errorCode

Property

Source
errorCode.ts typescript
errorCode: StatusCode

traceId

Property

Source
traceId.ts typescript
traceId: string

Methods

5 entries

getErrorResponse

Method

Source
getErrorResponse.ts typescript
getErrorResponse(traceId?: string): Readonly<ErrorResponsePayload>

Returns error response object

toJSON

Method

Source
toJSON.ts typescript
toJSON(): { data: unknown; message: string; name: string; stack: string | undefined; status: StatusCode; traceId: string }

toString

Method

Source
toString.ts typescript
toString(): string

Returns stringified error response object

fromError

Method

Source
fromError.ts typescript
fromError(err: unknown, errorCode?: StatusCode, data?: unknown, traceId?: string): HandledError

Creates a HandledError from an input. If the input error is a HandledError it will be returned without modifications.

fromMessage

Method

Source
fromMessage.ts typescript
fromMessage(message: Readonly<CommandErrorResponse>): HandledError

Create a error object from EBMessage error message