export class DecryptionError extends Error {
  public message: string = ''

  constructor(public inputError: unknown) {
    super()

    // Make sure inputError has access to the .message
    if (inputError instanceof Error) {
      if (inputError.message.toLowerCase().includes('expected')) {
        this.message = `The decryption key length or format is invalid.`
      } else if (
        inputError.message.includes('The JWK "alg" member was inconsistent')
      ) {
        this.message = `The decryption key is invalid.`
      } else {
        this.message =
          inputError.message || 'An error occurred while decrypting file.'
      }
    } else {
      // We don't have message on the inputError
      // Stringify whole error and set that as a message
      this.message =
        JSON.stringify(inputError) || 'An error occurred while decrypting file.'
    }

    this.name = 'DecryptionError'
    Object.setPrototypeOf(this, DecryptionError.prototype)
  }
}
