1 | import { AppError, ErrorData } from '@naturalcycles/js-lib'
|
2 | import { ValidationErrorItem } from 'joi'
|
3 |
|
4 | /**
|
5 | * Example of ValidationErrorItem:
|
6 | *
|
7 | * {
|
8 | * message: '"temperature" must be larger than or equal to 33',
|
9 | * path: [ 'entries', 10, 'temperature' ],
|
10 | * type: 'number.min',
|
11 | * context: { limit: 33, value: 30, key: 'temperature', label: 'temperature' }
|
12 | * }
|
13 | */
|
14 | export interface JoiValidationErrorData extends ErrorData {
|
15 | joiValidationErrorItems: ValidationErrorItem[]
|
16 | joiValidationObjectName?: string
|
17 | joiValidationObjectId?: string
|
18 | /**
|
19 | * Error "annotation" is stripped in Error.message.
|
20 | * This field contains the "full" annotation.
|
21 | *
|
22 | * This field is non-enumerable, won't be printed or included in JSON by default,
|
23 | * but still accessible programmatically (via `err.data.annotation`) when needed!
|
24 | */
|
25 | annotation?: string
|
26 | }
|
27 |
|
28 | export class JoiValidationError extends AppError<JoiValidationErrorData> {
|
29 | constructor(message: string, data: JoiValidationErrorData) {
|
30 | super(message, data)
|
31 | }
|
32 | }
|