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
Name | Type |
---|---|
errorCode | StatusCode |
message? | string |
data? | unknown |
traceId? | string |
Returns
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
Name | Type |
---|---|
traceId? | string |
Returns
Readonly
<ErrorResponsePayload
>
ErrorResponsePayload
Defined in
core/Error/HandledError.impl.ts:65
toJSON
▸ toJSON(): Object
Returns
Object
Name | Type | Description |
---|---|---|
data? | unknown | addition data |
message | string | a human readable error message |
name | string | - |
stack | undefined | string | - |
status | StatusCode | the error status code |
traceId? | string | the 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
Name | Type | Description |
---|---|---|
err | any | the input |
errorCode? | StatusCode | the error code |
data? | unknown | optional data |
traceId? | string | optional trace id |
Returns
HandledError
Defined in
core/Error/HandledError.impl.ts:45
fromMessage
▸ fromMessage(message
): HandledError
Create a error object from EBMessage error message
Parameters
Name | Type | Description |
---|---|---|
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