Skip to content

PURISTA API / Modules / @purista/core / HandledError

Class: HandledError

@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.

Hierarchy

  • Error

    HandledError

Table of contents

Constructors

Properties

Methods

Constructors

constructor

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

Parameters

NameType
errorCodeStatusCode
message?string
data?unknown
traceId?string

Returns

HandledError

Overrides

Error.constructor

Defined in

core/Error/HandledError.impl.ts:12

Properties

data

Optional data: unknown

Defined in

core/Error/HandledError.impl.ts:15


errorCode

errorCode: StatusCode

Defined in

core/Error/HandledError.impl.ts:13


traceId

Optional traceId: string

Defined in

core/Error/HandledError.impl.ts:16

Methods

getErrorResponse

getErrorResponse(traceId?): Readonly<ErrorResponsePayload>

Returns error response object

Parameters

NameType
traceId?string

Returns

Readonly<ErrorResponsePayload>

ErrorResponsePayload

Defined in

core/Error/HandledError.impl.ts:65


toJSON

toJSON(): Object

Returns

Object

NameTypeDescription
data?unknownaddition data
messagestringa human readable error message
namestring-
stackundefined | string-
statusStatusCodethe error status code
traceId?stringthe trace if of the request

Defined in

core/Error/HandledError.impl.ts:84


toString

toString(): string

Returns stringified error response object

Returns

string

ErrorResponse as string

Defined in

core/Error/HandledError.impl.ts:80


fromError

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

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

Parameters

NameTypeDescription
erranythe input
errorCode?StatusCodethe error code
data?unknownoptional data
traceId?stringoptional trace id

Returns

HandledError

HandledError

Defined in

core/Error/HandledError.impl.ts:45


fromMessage

fromMessage(message): HandledError

Create a error object from EBMessage error message

Parameters

NameTypeDescription
messageReadonly<{ 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

Defined in

core/Error/HandledError.impl.ts:31