1 | import { AppError, ErrorData } from '@naturalcycles/js-lib'
|
2 | import { ValidationErrorItem } from 'joi'
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export interface JoiValidationErrorData extends ErrorData {
|
15 | joiValidationErrorItems: ValidationErrorItem[]
|
16 | joiValidationObjectName?: string
|
17 | joiValidationObjectId?: string
|
18 | }
|
19 |
|
20 | export class JoiValidationError extends AppError<JoiValidationErrorData> {
|
21 | constructor(message: string, data: JoiValidationErrorData) {
|
22 | super(message, data)
|
23 |
|
24 | this.constructor = JoiValidationError
|
25 | ;(this as any).__proto__ = JoiValidationError.prototype
|
26 | Object.defineProperty(this, 'name', {
|
27 | value: this.constructor.name,
|
28 | configurable: true,
|
29 | })
|
30 |
|
31 | if (Error.captureStackTrace) {
|
32 | Error.captureStackTrace(this, this.constructor)
|
33 | } else {
|
34 | Object.defineProperty(this, 'stack', {
|
35 | value: new Error().stack,
|
36 | })
|
37 | }
|
38 | }
|
39 | }
|