All files / src/lib errors.ts

100% Statements 32/32
100% Branches 10/10
100% Functions 6/6
100% Lines 32/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 331x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 3x 3x 1x 1x 1x 1x 3x 1x 1x 2x 1x 1x 1x 1x 2x  
export class CleoBackendError extends Error {
  readonly code: string
  readonly cause?: unknown
 
  constructor(message: string, options: { code: string; cause?: unknown }) {
    super(message)
 
    this.name = "CleoBackendError"
    this.code = options.code
    this.cause = options.cause
  }
}
 
export function toErrorMessage(error: unknown) {
  if (error instanceof Error) {
    return error.message
  }
 
  if (typeof error === "string") {
    return error
  }
 
  return "Unknown error"
}
 
export function toErrorStack(error: unknown) {
  if (error instanceof Error) {
    return error.stack
  }
 
  return undefined
}