Skip to content

Commit

Permalink
feat: add context to signer error
Browse files Browse the repository at this point in the history
  • Loading branch information
RanGojo committed Jun 9, 2024
1 parent 8e1565a commit 5eff746
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/signer/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,28 @@ export type SignerOperationName =
| 'signMessage'

export class SignerError extends Error {
name = 'SignerError'
public readonly code: SignerErrorCode
public readonly root?: any
public readonly rpcCode?: RPCErrorCode
public readonly trace?: any
public context?: Record<string, unknown>
public _isSignerError = true

constructor(
code: SignerErrorCode,
m?: string | undefined,
root?: any,
rpcCode?: RPCErrorCode,
trace?: any
cause?: any,
context?: Record<string, unknown>
) {
super(m || getDefaultErrorMessage(code))
super(m || getDefaultErrorMessage(code), { cause })
Object.setPrototypeOf(this, SignerError.prototype)
SignerError.prototype._isSignerError = true
this.code = code
this.root = root
this.rpcCode = rpcCode
this.trace = trace
this.context = context
if (
this.code === SignerErrorCode.REJECTED_BY_USER ||
SignerError.isRejectedError(root)
Expand All @@ -93,6 +95,7 @@ export class SignerError extends Error {
'user denied',
'request rejected',
'user abort',
'disapproved',
'declined by user',
]
if (!!error && typeof error === 'string') {
Expand Down Expand Up @@ -132,6 +135,15 @@ export class SignerError extends Error {
)
}

getErrorContext(): Record<string, unknown> {
return {
code: this.code,
rpcCode: this.rpcCode,
message: this.message,
...(this.context || {}),
}
}

getErrorDetail(): {
code: SignerErrorCode
message: string
Expand Down

0 comments on commit 5eff746

Please sign in to comment.