All files / src/shared SdkErrorFromCode.ts

85.71% Statements 6/7
75% Branches 3/4
100% Functions 2/2
85.71% Lines 6/7

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 211x   1x   13x   13x       13x       13x            
import { SdkError, commonErrors } from '@affinidi/tools-common'
 
export default class SdkErrorFromCode extends SdkError {
  constructor(code: string, context: unknown = {}, originalError: unknown = {}) {
    const error = SdkErrorFromCode.errors[code]
 
    Iif (!error) {
      throw new Error(`Invalid operation error code: ${code}`)
    }
 
    super({ ...error, code }, context, originalError)
  }
 
  static get errors(): any {
    return {
      ...commonErrors,
      // NOTE: errors related to SDK only should be added here with a separate prefix SDK-XXX (SDK-1), not to commonErrors
    }
  }
}