1 2
import BaseError = require('extensible-error')
2
import { ErrorObject } from 'ajv'
3

4 2
import { Errors } from 'ilp-packet'
5

6 2
export default class InvalidJsonBodyError extends BaseError {
7
  public ilpErrorCode: string
8 2
  public httpErrorCode: number = 400
9
  protected validationErrors: ErrorObject[]
10

11
  constructor (message: string, validationErrors: ErrorObject[]) {
12 2
    super(message)
13

14 2
    this.ilpErrorCode = Errors.codes.F01_INVALID_PACKET
15 2
    this.validationErrors = validationErrors
16
  }
17

18
  debugPrint (log: (message: string) => void, validationError?: ErrorObject) {
19 2
    if (!validationError) {
20 2
      if (this.validationErrors) {
21 0
        for (let ve of this.validationErrors) {
22 0
          this.debugPrint(log, ve)
23
        }
24
      }
25 0
      return
26
    }
27

28 0
    const additionalInfo = Object.keys(validationError.params).map(key => `${key}=${validationError.params[key]}`).join(' ')
29

30 0
    log(`-- ${validationError.dataPath}: ${validationError.message}. ${additionalInfo}`)
31
  }
32
}

Read our documentation on viewing source code .

Loading