Skip to main content

Class: HandledError


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:10open in new window

Properties

data

Optional data: unknown

Defined in

core/Error/HandledError.impl.ts:13open in new window


errorCode

errorCode: StatusCode

Defined in

core/Error/HandledError.impl.ts:11open in new window


traceId

Optional traceId: string

Defined in

core/Error/HandledError.impl.ts:14open in new window

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:53open in new window


toString

toString(): string

Returns stringified error response object

Returns

string

ErrorResponse as string

Defined in

core/Error/HandledError.impl.ts:68open in new window


fromError

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

Creates a HandledError from an input

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:42open in new window


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: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>CommandErrorResponse

Returns

HandledError

HandledError

Defined in

core/Error/HandledError.impl.ts:29open in new window

Last update:
Contributors: Sebastian Wessel