All files / src errors.ts

85.19% Statements 46/54
62.5% Branches 5/8
76.92% Functions 10/13
85.19% Lines 46/54

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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179        1x               1x                           1x               25x 25x 25x 25x       1x               1x   1x 1x             1x                   1x   4x 4x             1x       5x 5x             1x   1x 1x             1x       2x 2x 2x 2x 2x               1x           1x   1x 1x 1x 1x 1x             1x   2x 2x 2x 2x             1x   9x 9x 9x 9x             1x                     1x              
 
/**
* @ignore
*/
export const ERROR_CODES = {
  MISSING_PARAMETER: 'missing_parameter',
  REMOTE_SERVICE_ERROR: 'remote_service_error',
  INVALID_STATE: 'invalid_state',
  NO_SESSION_DATA: 'no_session_data',
  UNKNOWN: 'unknown'
}
 
Object.freeze(ERROR_CODES)
 
/**
* @ignore
*/
type ErrorType = {
  code: string,
  parameter?: string,
  message: string
}
 
/**
* @ignore
*/
export class BlockstackError extends Error {
  message: string
 
  code: string
 
  parameter?: string
 
  constructor(error: ErrorType) {
    super(error.message)
    this.message = error.message
    this.code = error.code
    this.parameter = error.parameter ? error.parameter : null
  }
 
  toString() {
    return `${super.toString()}
    code: ${this.code} param: ${this.parameter ? this.parameter : 'n/a'}`
  }
}
 
/**
* @ignore
*/
export class FileNotFound extends BlockstackError {
  constructor(message: string) {
    super({ message, code: 'file_not_found' })
    this.name = 'FileNotFound'
  }
}
 
/**
* @ignore
*/
export class InvalidParameterError extends BlockstackError {
  constructor(parameter: string, message: string = '') {
    super({ code: 'missing_parameter', message, parameter: '' })
    this.name = 'MissingParametersError'
  }
}
 
/**
* @ignore
*/
export class MissingParameterError extends BlockstackError {
  constructor(parameter: string, message: string = '') {
    super({ code: ERROR_CODES.MISSING_PARAMETER, message, parameter })
    this.name = 'MissingParametersError'
  }
}
 
/**
* @ignore
*/
export class RemoteServiceError extends BlockstackError {
  response: Response
 
  constructor(response: Response, message: string = '') {
    super({ code: ERROR_CODES.REMOTE_SERVICE_ERROR, message })
    this.response = response
  }
}
 
/**
* @ignore
*/
export class InvalidDIDError extends BlockstackError {
  constructor(message: string = '') {
    super({ code: 'invalid_did_error', message })
    this.name = 'InvalidDIDError'
  }
}
 
/**
* @ignore
*/
export class NotEnoughFundsError extends BlockstackError {
  leftToFund: number
 
  constructor(leftToFund: number) {
    const message = `Not enough UTXOs to fund. Left to fund: ${leftToFund}`
    super({ code: 'not_enough_error', message })
    this.leftToFund = leftToFund
    this.name = 'NotEnoughFundsError'
    this.message = message
  }
}
 
/**
* @ignore
*/
 
export class InvalidAmountError extends BlockstackError {
  fees: number
 
  specifiedAmount: number
 
  constructor(fees: number, specifiedAmount: number) {
    const message = `Not enough coin to fund fees transaction fees. Fees would be ${fees},`
          + ` specified spend is  ${specifiedAmount}`
    super({ code: 'invalid_amount_error', message })
    this.specifiedAmount = specifiedAmount
    this.fees = fees
    this.name = 'InvalidAmountError'
    this.message = message
  }
}
 
/**
* @ignore
*/
export class LoginFailedError extends BlockstackError {
  constructor(reason: string) {
    const message = `Failed to login: ${reason}`
    super({ code: 'login_failed', message })
    this.message = message
    this.name = 'LoginFailedError'
  }
}
 
/**
* @ignore
*/
export class SignatureVerificationError extends BlockstackError {
  constructor(reason: string) {
    const message = `Failed to verify signature: ${reason}`
    super({ code: 'signature_verification_failure', message })
    this.message = message
    this.name = 'SignatureVerificationError'
  }
}
 
/**
* @ignore
*/
export class InvalidStateError extends BlockstackError {
  constructor(message: string) {
    super({ code: ERROR_CODES.INVALID_STATE, message })
    this.message = message
    this.name = 'InvalidStateError'
  }
}
 
/**
* @ignore
*/
export class NoSessionDataError extends BlockstackError {
  constructor(message: string) {
    super({ code: ERROR_CODES.INVALID_STATE, message })
    this.message = message
    this.name = 'NoSessionDataError'
  }
}