Skip to content

@purista/core v2.0.5


PURISTA API / @purista/core / HandledError

Class: HandledError

Defined in: packages/core/src/core/Error/HandledError.impl.ts:11

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.

Extends

  • Error

Constructors

new HandledError()

new HandledError(errorCode, message?, data?, traceId?): HandledError

Defined in: packages/core/src/core/Error/HandledError.impl.ts:12

Parameters

errorCode

StatusCode

message?

string

data?

unknown

traceId?

string

Returns

HandledError

Overrides

Error.constructor

Properties

data?

optional data: unknown

Defined in: packages/core/src/core/Error/HandledError.impl.ts:15


errorCode

errorCode: StatusCode

Defined in: packages/core/src/core/Error/HandledError.impl.ts:13


traceId?

optional traceId: string

Defined in: packages/core/src/core/Error/HandledError.impl.ts:16

Methods

getErrorResponse()

getErrorResponse(traceId?): Readonly<ErrorResponsePayload>

Defined in: packages/core/src/core/Error/HandledError.impl.ts:65

Returns error response object

Parameters

traceId?

string

Returns

Readonly<ErrorResponsePayload>

ErrorResponsePayload


toJSON()

toJSON(): object

Defined in: packages/core/src/core/Error/HandledError.impl.ts:84

Returns

object

data?

optional data: unknown

addition data

message

message: string

a human readable error message

name

name: string

stack

stack: undefined | string

status

status: StatusCode

the error status code

traceId?

optional traceId: string

the trace if of the request


toString()

toString(): string

Defined in: packages/core/src/core/Error/HandledError.impl.ts:80

Returns stringified error response object

Returns

string

ErrorResponse as string


fromError()

static fromError(err, errorCode?, data?, traceId?): HandledError

Defined in: packages/core/src/core/Error/HandledError.impl.ts:45

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

Parameters

err

any

the input

errorCode?

StatusCode

the error code

data?

unknown

optional data

traceId?

string

optional trace id

Returns

HandledError

HandledError


fromMessage()

static fromMessage(message): HandledError

Defined in: packages/core/src/core/Error/HandledError.impl.ts:31

Create a error object from EBMessage error message

Parameters

message

Readonly<{ contentEncoding: "utf-8"; contentType: "application/json"; correlationId: string; eventName: string; id: string; isHandledError: boolean; messageType: CommandErrorResponse; otp: string; payload: { data: unknown; message: string; status: StatusCode; }; principalId: string; receiver: { instanceId: string; serviceName: string; serviceTarget: string; serviceVersion: string; }; sender: { instanceId: string; serviceName: string; serviceTarget: string; serviceVersion: string; }; tenantId: string; timestamp: number; traceId: string; }>

CommandErrorResponse

Returns

HandledError

HandledError