1 | import {SerializePath} from './StructureNodes'
|
2 |
|
3 | export class SerializeError extends Error {
|
4 | public readonly path: SerializePath
|
5 | public helpId?: HELP_URL
|
6 |
|
7 | constructor(
|
8 | message: string,
|
9 | parentPath: SerializePath,
|
10 | pathSegment: string | number | undefined,
|
11 | hint?: string
|
12 | ) {
|
13 | super(message)
|
14 | const segment = typeof pathSegment === 'undefined' ? '<unknown>' : `${pathSegment}`
|
15 | this.path = (parentPath || []).concat(hint ? `${segment} (${hint})` : segment)
|
16 | }
|
17 |
|
18 | withHelpUrl(id: HELP_URL): SerializeError {
|
19 | this.helpId = id
|
20 | return this
|
21 | }
|
22 | }
|
23 |
|
24 | export enum HELP_URL {
|
25 | ID_REQUIRED = 'structure-node-id-required',
|
26 | TITLE_REQUIRED = 'structure-title-required',
|
27 | FILTER_REQUIRED = 'structure-filter-required',
|
28 | INVALID_LIST_ITEM = 'structure-invalid-list-item',
|
29 | DOCUMENT_ID_REQUIRED = 'structure-document-id-required',
|
30 | SCHEMA_TYPE_REQUIRED = 'structure-schema-type-required',
|
31 | SCHEMA_TYPE_NOT_FOUND = 'structure-schema-type-not-found',
|
32 | LIST_ITEMS_MUST_BE_ARRAY = 'structure-list-items-must-be-array',
|
33 | QUERY_PROVIDED_FOR_FILTER = 'structure-query-provided-for-filter',
|
34 | ACTION_OR_INTENT_REQUIRED = 'structure-action-or-intent-required',
|
35 | LIST_ITEM_IDS_MUST_BE_UNIQUE = 'structure-list-item-ids-must-be-unique',
|
36 | ACTION_AND_INTENT_MUTUALLY_EXCLUSIVE = 'structure-action-and-intent-mutually-exclusive'
|
37 | }
|