@gala-chain/api ∙ API
API > ChainError
Class: abstract
ChainError
Contents
- Extends
- Implements
- Constructors
- new ChainError(message)
- new ChainError(message, key)
- new ChainError(message, key, payload)
- new ChainError(message, payload)
- Properties
- code
- key
- message
- name
- payload
- stack
- prepareStackTrace
- stackTraceLimit
- Methods
- andExec()
- logError()
- logWarn()
- map()
- matches()
- captureStackTrace()
- from()
- isChainError()
- map()
- matches()
- normalizedKey()
- withCode()
Extends
Error
Implements
Constructors
new ChainError(message)
new ChainError(
message
):ChainError
Parameters
▪ message: string
Overrides
Error.constructor
Source
chain-api/src/utils/error.ts:59
new ChainError(message, key)
new ChainError(
message
,key
):ChainError
Parameters
▪ message: string
▪ key: Uppercase
\<string
>
Overrides
Error.constructor
Source
chain-api/src/utils/error.ts:60
new ChainError(message, key, payload)
new ChainError(
message
,key
,payload
):ChainError
Parameters
▪ message: string
▪ key: Uppercase
\<string
>
▪ payload: Record
\<string
, unknown
>
Overrides
Error.constructor
Source
chain-api/src/utils/error.ts:61
new ChainError(message, payload)
new ChainError(
message
,payload
):ChainError
Parameters
▪ message: string
▪ payload: unknown
Overrides
Error.constructor
Source
chain-api/src/utils/error.ts:62
Properties
code
readonly
code:ErrorCode
Status code, a value from ErrorCode enum. It is directly mapped to HTTP, status, it is a constant value to be used by clients integrating with the chain.
Implementation of
Source
chain-api/src/utils/error.ts:45
key
readonly
key:Uppercase
\<string
>
An upper case string to be used as a key do diagnose where the error comes from and help with regular development. It should not be used by client integrating with the chain since we don't guarantee it won't change. It is generated from original error class name.
Implementation of
Source
chain-api/src/utils/error.ts:53
message
message:
string
Implementation of
OptionalChainErrorData
.message
Inherited from
Error.message
Source
node_modules/typescript/lib/lib.es5.d.ts:1076
name
name:
string
Inherited from
Error.name
Source
node_modules/typescript/lib/lib.es5.d.ts:1075
payload
readonly
payload?:Record
\<string
,unknown
>
Additional information to be used by
Implementation of
OptionalChainErrorData
.payload
Source
chain-api/src/utils/error.ts:58
stack
stack?:
string
Inherited from
Error.stack
Source
node_modules/typescript/lib/lib.es5.d.ts:1077
prepareStackTrace
static
prepareStackTrace?: (err
,stackTraces
) =>any
Optional override for formatting stack traces
Parameters
▪ err: Error
▪ stackTraces: CallSite
[]
Returns
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Error.prepareStackTrace
Source
node_modules/@types/node/globals.d.ts:11
stackTraceLimit
static
stackTraceLimit:number
Inherited from
Error.stackTraceLimit
Source
node_modules/@types/node/globals.d.ts:13
Methods
andExec()
andExec(
fn
):ChainError
Allows to execute function getting as a parameter the current error.
Parameters
▪ fn: (e
) => void
Returns
Example
Source
chain-api/src/utils/error.ts:114
logError()
logError(
logger
):ChainError
Parameters
▪ logger: object
▪ logger.error
Source
chain-api/src/utils/error.ts:119
logWarn()
logWarn(
logger
):ChainError
Parameters
▪ logger: object
▪ logger.warn
Source
chain-api/src/utils/error.ts:124
map()
map(
key
,newError
):ChainError
Maps ChainError to another chain error by error code if key
param matches
current error code or current diagnostic key. Otherwise, returns original
error.
Useful in rethrowing an error or mapping an error to another one in catch clauses or catch methods in promises.
Parameters
▪ key: ErrorCode
| ClassConstructor
\<ChainError
>
error code or error class to match
▪ newError: ChainError
| (e
) => ChainError
new error or a function to create the new error
Source
chain-api/src/utils/error.ts:148
matches()
matches(
key
):boolean
Parameters
▪ key: ErrorCode
| ClassConstructor
\<ChainError
>
Source
chain-api/src/utils/error.ts:129
captureStackTrace()
static
captureStackTrace(targetObject
,constructorOpt
?):void
Create .stack property on a target object
Parameters
▪ targetObject: object
▪ constructorOpt?: Function
Inherited from
Error.captureStackTrace
Source
node_modules/@types/node/globals.d.ts:4
from()
static
from(e
):ChainError
Parameters
▪ e: object
& object
Source
chain-api/src/utils/error.ts:168
isChainError()
static
isChainError(e
):e is ChainError
Parameters
▪ e: undefined
| object
Source
chain-api/src/utils/error.ts:164
map()
static
map(e
,key
,newError
):ChainError
Maps ChainError to another chain error by error code, or returns original error if no error code matches, or returns default chain error if a given parameter is not a ChainError instance.
Useful in rethrowing an error or mapping an error to another one in catch clauses or catch methods in promises.
Parameters
▪ e: ChainError
| object
original error
▪ key: ErrorCode
| ClassConstructor
\<ChainError
>
error code or error class to match
▪ newError: ChainError
| (e
) => ChainError
new error or a function to create the new error
Source
chain-api/src/utils/error.ts:191
matches()
static
matches(e
,key
):boolean
Parameters
▪ e: ChainError
| object
▪ key: ErrorCode
| ClassConstructor
\<ChainError
>
Source
chain-api/src/utils/error.ts:172
normalizedKey()
static
normalizedKey(fn
):Uppercase
\<string
>
Parameters
▪ fn: string
| Function
Source
chain-api/src/utils/error.ts:80
withCode()
static
withCode(code
):ClassConstructor
\<ChainError
>
Parameters
▪ code: ErrorCode