@devp0nt/error0 1.0.0-next.17 → 1.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.d.cts +198 -194
- package/dist/cjs/index.js +19 -32
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +198 -194
- package/dist/esm/index.js +17 -31
- package/dist/esm/index.js.map +1 -1
- package/package.json +4 -5
- package/src/index.test.ts +6 -14
- package/src/index.ts +117 -140
package/src/index.ts
CHANGED
|
@@ -1,71 +1,81 @@
|
|
|
1
1
|
import { Meta0 } from '@devp0nt/meta0'
|
|
2
|
-
import { meta0PluginTag } from '@devp0nt/meta0/plugins/meta0-plugin-tag'
|
|
3
2
|
import { type AxiosError, HttpStatusCode, isAxiosError } from 'axios'
|
|
4
3
|
import get from 'lodash/get.js'
|
|
5
4
|
import { ZodError } from 'zod'
|
|
6
5
|
|
|
7
|
-
// TODO: Эррор 0 можно передать и вторым аргументом в логгер, тогда её месадж попадёт в мету, а первый месадж в сам месадж логера
|
|
8
|
-
// TODO: Зод, аксиос, это всё плагины
|
|
9
|
-
// TODO: В эррор0 добавить ориджинал
|
|
10
6
|
// TODO: store tags as array from all causes
|
|
11
7
|
// TODO: not use self stack if toError0
|
|
12
8
|
// TODO: fix default message in extended error0, should be used in constuctor of Error0
|
|
13
9
|
// TODO: remove defaults prop from getPropsFromUnknown
|
|
14
10
|
// TODO: code has enum type, fn to check if code exists
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return undefined
|
|
12
|
+
export interface Error0Input {
|
|
13
|
+
message?: string
|
|
14
|
+
tag?: string
|
|
15
|
+
code?: string
|
|
16
|
+
httpStatus?: HttpStatusCode | HttpStatusCodeString
|
|
17
|
+
expected?: boolean | ExpectedFn
|
|
18
|
+
clientMessage?: string
|
|
19
|
+
cause?: Error0Cause
|
|
20
|
+
stack?: string
|
|
21
|
+
meta?: Meta0.Meta0OrValueTypeNullish
|
|
22
|
+
zodError?: ZodError
|
|
23
|
+
axiosError?: AxiosError
|
|
29
24
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
|
|
26
|
+
interface Error0GeneralProps {
|
|
27
|
+
message: Error0Input['message']
|
|
28
|
+
tag: Error0Input['tag']
|
|
29
|
+
code: Error0Input['code']
|
|
30
|
+
httpStatus: number | undefined
|
|
31
|
+
expected: boolean | undefined
|
|
32
|
+
clientMessage: Error0Input['clientMessage']
|
|
33
|
+
anyMessage: string | undefined
|
|
34
|
+
cause: Error0Input['cause']
|
|
35
|
+
stack: Error['stack']
|
|
36
|
+
meta: Meta0.ValueType
|
|
37
|
+
zodError?: ZodError
|
|
38
|
+
axiosError?: AxiosError
|
|
35
39
|
}
|
|
36
40
|
|
|
41
|
+
type HttpStatusCodeString = keyof typeof HttpStatusCode
|
|
42
|
+
type Error0Cause = Error | Error0 | unknown
|
|
43
|
+
type ExpectedFn = (error: Error0GeneralProps) => boolean | undefined
|
|
44
|
+
|
|
45
|
+
const isFilled = <T>(value: T): value is NonNullable<T> => value !== null && value !== undefined && value !== ''
|
|
46
|
+
|
|
37
47
|
export class Error0 extends Error {
|
|
38
48
|
public readonly __I_AM_ERROR_0: true = true
|
|
39
49
|
|
|
40
|
-
public readonly tag?:
|
|
41
|
-
public readonly code?:
|
|
42
|
-
public readonly httpStatus?:
|
|
43
|
-
public readonly expected?:
|
|
44
|
-
public readonly clientMessage?:
|
|
45
|
-
public readonly anyMessage?:
|
|
46
|
-
public override readonly cause?:
|
|
47
|
-
public readonly meta?: Meta0.
|
|
48
|
-
public readonly zodError?:
|
|
49
|
-
public readonly axiosError?:
|
|
50
|
+
public readonly tag?: Error0GeneralProps['tag']
|
|
51
|
+
public readonly code?: Error0GeneralProps['code']
|
|
52
|
+
public readonly httpStatus?: Error0GeneralProps['httpStatus']
|
|
53
|
+
public readonly expected?: Error0GeneralProps['expected']
|
|
54
|
+
public readonly clientMessage?: Error0GeneralProps['clientMessage']
|
|
55
|
+
public readonly anyMessage?: Error0GeneralProps['anyMessage']
|
|
56
|
+
public override readonly cause?: Error0GeneralProps['cause']
|
|
57
|
+
public readonly meta?: Meta0.Meta0OrValueTypeNullish
|
|
58
|
+
public readonly zodError?: Error0GeneralProps['zodError']
|
|
59
|
+
public readonly axiosError?: Error0GeneralProps['axiosError']
|
|
50
60
|
|
|
51
61
|
static defaultMessage = 'Unknown error'
|
|
52
|
-
static defaultCode?:
|
|
53
|
-
static defaultHttpStatus?:
|
|
54
|
-
static defaultExpected?:
|
|
55
|
-
static defaultClientMessage?:
|
|
62
|
+
static defaultCode?: Error0GeneralProps['code']
|
|
63
|
+
static defaultHttpStatus?: Error0GeneralProps['httpStatus']
|
|
64
|
+
static defaultExpected?: Error0GeneralProps['expected']
|
|
65
|
+
static defaultClientMessage?: Error0GeneralProps['clientMessage']
|
|
56
66
|
static defaultMeta?: Meta0.Meta0OrValueTypeNullish
|
|
57
67
|
|
|
58
|
-
public readonly propsOriginal:
|
|
68
|
+
public readonly propsOriginal: Error0GeneralProps
|
|
59
69
|
|
|
60
70
|
constructor(message: string)
|
|
61
|
-
constructor(input:
|
|
62
|
-
constructor(message: string, input:
|
|
71
|
+
constructor(input: Error0Input)
|
|
72
|
+
constructor(message: string, input: Error0Input)
|
|
63
73
|
constructor(error: Error)
|
|
64
|
-
constructor(error: Error, input:
|
|
74
|
+
constructor(error: Error, input: Error0Input)
|
|
65
75
|
constructor(value: unknown)
|
|
66
|
-
constructor(value: unknown, input:
|
|
76
|
+
constructor(value: unknown, input: Error0Input)
|
|
67
77
|
constructor(...args: unknown[]) {
|
|
68
|
-
const input: Partial<
|
|
78
|
+
const input: Partial<Error0Input> = {}
|
|
69
79
|
if (args[0] instanceof Error) {
|
|
70
80
|
input.cause = args[0]
|
|
71
81
|
} else if (typeof args[0] === 'object' && args[0] !== null) {
|
|
@@ -111,8 +121,8 @@ export class Error0 extends Error {
|
|
|
111
121
|
|
|
112
122
|
// props
|
|
113
123
|
|
|
114
|
-
public static _safeParseInput(error0Input: Record<string, unknown>):
|
|
115
|
-
const result:
|
|
124
|
+
public static _safeParseInput(error0Input: Record<string, unknown>): Error0Input {
|
|
125
|
+
const result: Error0Input = {}
|
|
116
126
|
result.message = typeof error0Input.message === 'string' ? error0Input.message : undefined
|
|
117
127
|
result.tag = typeof error0Input.tag === 'string' ? error0Input.tag : undefined
|
|
118
128
|
result.code = typeof error0Input.code === 'string' ? error0Input.code : undefined
|
|
@@ -149,27 +159,19 @@ export class Error0 extends Error {
|
|
|
149
159
|
message,
|
|
150
160
|
stack,
|
|
151
161
|
}: {
|
|
152
|
-
error0Input:
|
|
162
|
+
error0Input: Error0Input
|
|
153
163
|
message: string
|
|
154
|
-
stack:
|
|
155
|
-
}):
|
|
164
|
+
stack: Error0GeneralProps['stack']
|
|
165
|
+
}): Error0GeneralProps {
|
|
156
166
|
// const meta = Meta0.merge(error0Input.meta0, error0Input.meta).value
|
|
157
|
-
|
|
158
|
-
// const meta0 = Meta0.extend(error0Input.meta, this.defaultMeta)
|
|
159
|
-
// const defaultMetaValue =
|
|
160
|
-
// this.defaultMeta && typeof this.defaultMeta === 'object' && 'getValue' in this.defaultMeta
|
|
161
|
-
// ? (this.defaultMeta as any).getValue()
|
|
162
|
-
// : this.defaultMeta
|
|
163
|
-
|
|
164
|
-
const meta0 = Meta0.extend(this.defaultMeta, error0Input.meta)
|
|
167
|
+
const meta0 = Meta0.extend(error0Input.meta, this.defaultMeta)
|
|
165
168
|
const meta = meta0.getValue()
|
|
166
|
-
const finalTag =
|
|
167
|
-
delete meta.tagPrefix
|
|
169
|
+
const finalTag = meta0.getFinalTag(error0Input.tag)
|
|
168
170
|
const clientMessage = error0Input.clientMessage || this.defaultClientMessage
|
|
169
|
-
const result:
|
|
171
|
+
const result: Error0GeneralProps = {
|
|
170
172
|
message: error0Input.message || this.defaultMessage,
|
|
171
173
|
tag: finalTag,
|
|
172
|
-
code: error0Input.code ||
|
|
174
|
+
code: error0Input.code || meta.code || this.defaultCode,
|
|
173
175
|
httpStatus:
|
|
174
176
|
typeof error0Input.httpStatus === 'number'
|
|
175
177
|
? error0Input.httpStatus
|
|
@@ -177,7 +179,7 @@ export class Error0 extends Error {
|
|
|
177
179
|
typeof error0Input.httpStatus === 'string' &&
|
|
178
180
|
error0Input.httpStatus in HttpStatusCode
|
|
179
181
|
? HttpStatusCode[error0Input.httpStatus]
|
|
180
|
-
:
|
|
182
|
+
: meta.httpStatus || this.defaultHttpStatus,
|
|
181
183
|
expected: undefined,
|
|
182
184
|
clientMessage,
|
|
183
185
|
anyMessage: clientMessage || message,
|
|
@@ -191,19 +193,19 @@ export class Error0 extends Error {
|
|
|
191
193
|
result,
|
|
192
194
|
typeof error0Input.expected === 'boolean' || typeof error0Input.expected === 'function'
|
|
193
195
|
? error0Input.expected
|
|
194
|
-
:
|
|
196
|
+
: meta.expected || this.defaultExpected,
|
|
195
197
|
)
|
|
196
198
|
result.stack = this._removeConstructorStackPart(stack)
|
|
197
199
|
return result
|
|
198
200
|
}
|
|
199
201
|
|
|
200
|
-
public static _getSelfPropsFloated(causesProps:
|
|
202
|
+
public static _getSelfPropsFloated(causesProps: Error0GeneralProps[]): Error0GeneralProps {
|
|
201
203
|
const cause = this._getClosestPropValue(causesProps, 'cause')
|
|
202
204
|
const stack = this._mergeStack(causesProps[1]?.stack, causesProps[0]?.stack)
|
|
203
205
|
const closestTag = this._getClosestPropValue(causesProps, 'tag')
|
|
204
206
|
const meta = this._getMergedMetaValue(causesProps)
|
|
205
|
-
const tag =
|
|
206
|
-
const propsFloated:
|
|
207
|
+
const tag = Meta0.getFinalTag(meta, closestTag)
|
|
208
|
+
const propsFloated: Error0GeneralProps = {
|
|
207
209
|
message: this._getClosestPropValue(causesProps, 'message'),
|
|
208
210
|
tag,
|
|
209
211
|
code: this._getClosestPropValue(causesProps, 'code'),
|
|
@@ -222,13 +224,13 @@ export class Error0 extends Error {
|
|
|
222
224
|
|
|
223
225
|
// sepcial
|
|
224
226
|
|
|
225
|
-
public static _getExtraError0PropsByZodError(zodError: ZodError): Partial<
|
|
227
|
+
public static _getExtraError0PropsByZodError(zodError: ZodError): Partial<Error0GeneralProps> {
|
|
226
228
|
return {
|
|
227
229
|
message: `Zod Validation Error: ${zodError.message}`,
|
|
228
230
|
}
|
|
229
231
|
}
|
|
230
232
|
|
|
231
|
-
public static _getExtraError0PropsByAxiosError(axiosError: AxiosError): Partial<
|
|
233
|
+
public static _getExtraError0PropsByAxiosError(axiosError: AxiosError): Partial<Error0GeneralProps> {
|
|
232
234
|
return {
|
|
233
235
|
message: 'Axios Error',
|
|
234
236
|
meta: {
|
|
@@ -245,8 +247,8 @@ export class Error0 extends Error {
|
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
public static _assignError0Props(
|
|
248
|
-
error0Props:
|
|
249
|
-
extraError0Props: Partial<
|
|
250
|
+
error0Props: Error0GeneralProps,
|
|
251
|
+
extraError0Props: Partial<Error0GeneralProps>,
|
|
250
252
|
): void {
|
|
251
253
|
const metaValue = Meta0.mergeValues(error0Props.meta, extraError0Props.meta)
|
|
252
254
|
Object.assign(error0Props, extraError0Props, { meta: metaValue })
|
|
@@ -255,8 +257,8 @@ export class Error0 extends Error {
|
|
|
255
257
|
// expected
|
|
256
258
|
|
|
257
259
|
public static _normalizeSelfExpected(
|
|
258
|
-
error0Props:
|
|
259
|
-
expectedProvided:
|
|
260
|
+
error0Props: Error0GeneralProps,
|
|
261
|
+
expectedProvided: Error0Input['expected'],
|
|
260
262
|
): boolean | undefined {
|
|
261
263
|
if (typeof expectedProvided === 'function') {
|
|
262
264
|
return expectedProvided(error0Props)
|
|
@@ -264,7 +266,7 @@ export class Error0 extends Error {
|
|
|
264
266
|
return expectedProvided
|
|
265
267
|
}
|
|
266
268
|
|
|
267
|
-
public static _isExpected(causesProps:
|
|
269
|
+
public static _isExpected(causesProps: Error0GeneralProps[]): boolean {
|
|
268
270
|
let hasExpectedTrue = false
|
|
269
271
|
for (const causeProps of causesProps) {
|
|
270
272
|
if (causeProps.expected === false) {
|
|
@@ -279,7 +281,7 @@ export class Error0 extends Error {
|
|
|
279
281
|
|
|
280
282
|
// getters
|
|
281
283
|
|
|
282
|
-
public static _getPropsFromUnknown(error: unknown, defaults?:
|
|
284
|
+
public static _getPropsFromUnknown(error: unknown, defaults?: Error0Input): Error0GeneralProps {
|
|
283
285
|
if (typeof error !== 'object' || error === null) {
|
|
284
286
|
return {
|
|
285
287
|
message: undefined,
|
|
@@ -301,7 +303,7 @@ export class Error0 extends Error {
|
|
|
301
303
|
'clientMessage' in error && typeof error.clientMessage === 'string'
|
|
302
304
|
? error.clientMessage
|
|
303
305
|
: defaults?.clientMessage || undefined
|
|
304
|
-
const result:
|
|
306
|
+
const result: Error0GeneralProps = {
|
|
305
307
|
message,
|
|
306
308
|
code: 'code' in error && typeof error.code === 'string' ? error.code : defaults?.code || undefined,
|
|
307
309
|
clientMessage,
|
|
@@ -336,7 +338,7 @@ export class Error0 extends Error {
|
|
|
336
338
|
result.expected = this._normalizeSelfExpected(
|
|
337
339
|
result,
|
|
338
340
|
'expected' in error && (typeof error.expected === 'boolean' || typeof error.expected === 'function')
|
|
339
|
-
? (error.expected as
|
|
341
|
+
? (error.expected as ExpectedFn)
|
|
340
342
|
: defaults?.expected || undefined,
|
|
341
343
|
)
|
|
342
344
|
if (result.zodError) {
|
|
@@ -348,12 +350,12 @@ export class Error0 extends Error {
|
|
|
348
350
|
return result
|
|
349
351
|
}
|
|
350
352
|
|
|
351
|
-
public static _getCausesPropsFromUnknown(error: unknown, maxLevel: number):
|
|
353
|
+
public static _getCausesPropsFromUnknown(error: unknown, maxLevel: number): Error0GeneralProps[] {
|
|
352
354
|
if (!error) {
|
|
353
355
|
return []
|
|
354
356
|
}
|
|
355
357
|
const causeProps = this._getPropsFromUnknown(error)
|
|
356
|
-
const causesProps:
|
|
358
|
+
const causesProps: Error0GeneralProps[] = [causeProps]
|
|
357
359
|
if (!causeProps.cause) {
|
|
358
360
|
return causesProps
|
|
359
361
|
}
|
|
@@ -364,28 +366,28 @@ export class Error0 extends Error {
|
|
|
364
366
|
}
|
|
365
367
|
|
|
366
368
|
public static _getCausesPropsFromError0Props(
|
|
367
|
-
error0Props:
|
|
369
|
+
error0Props: Error0GeneralProps,
|
|
368
370
|
maxLevel: number,
|
|
369
|
-
):
|
|
371
|
+
): Error0GeneralProps[] {
|
|
370
372
|
return [error0Props, ...this._getCausesPropsFromUnknown(error0Props.cause, maxLevel - 1)]
|
|
371
373
|
}
|
|
372
374
|
|
|
373
|
-
public static _getClosestPropValue<TPropKey extends keyof
|
|
374
|
-
causesProps:
|
|
375
|
+
public static _getClosestPropValue<TPropKey extends keyof Error0GeneralProps>(
|
|
376
|
+
causesProps: Error0GeneralProps[],
|
|
375
377
|
propKey: TPropKey,
|
|
376
|
-
): NonNullable<
|
|
378
|
+
): NonNullable<Error0GeneralProps[TPropKey]> | undefined {
|
|
377
379
|
for (const causeProps of causesProps) {
|
|
378
380
|
const propValue = causeProps[propKey]
|
|
379
381
|
if (isFilled(propValue)) {
|
|
380
|
-
return propValue as NonNullable<
|
|
382
|
+
return propValue as NonNullable<Error0GeneralProps[TPropKey]>
|
|
381
383
|
}
|
|
382
384
|
}
|
|
383
385
|
return undefined
|
|
384
386
|
}
|
|
385
387
|
|
|
386
388
|
// private static getClosestByGetter<TResult>(
|
|
387
|
-
// causesProps:
|
|
388
|
-
// getter: (props:
|
|
389
|
+
// causesProps: Error0GeneralProps[],
|
|
390
|
+
// getter: (props: Error0GeneralProps) => TResult,
|
|
389
391
|
// ): NonNullable<TResult> | undefined {
|
|
390
392
|
// for (const causeProps of causesProps) {
|
|
391
393
|
// const result = getter(causeProps)
|
|
@@ -396,21 +398,21 @@ export class Error0 extends Error {
|
|
|
396
398
|
// return undefined
|
|
397
399
|
// }
|
|
398
400
|
|
|
399
|
-
public static _getFilledPropValues<TPropKey extends keyof
|
|
400
|
-
causesProps:
|
|
401
|
+
public static _getFilledPropValues<TPropKey extends keyof Error0Input>(
|
|
402
|
+
causesProps: Error0GeneralProps[],
|
|
401
403
|
propKey: TPropKey,
|
|
402
|
-
): NonNullable<
|
|
403
|
-
const values: NonNullable<
|
|
404
|
+
): NonNullable<Error0GeneralProps[TPropKey]>[] {
|
|
405
|
+
const values: NonNullable<Error0GeneralProps[TPropKey]>[] = []
|
|
404
406
|
for (const causeProps of causesProps) {
|
|
405
407
|
const propValue = causeProps[propKey]
|
|
406
408
|
if (isFilled(propValue)) {
|
|
407
|
-
values.push(propValue as NonNullable<
|
|
409
|
+
values.push(propValue as NonNullable<Error0GeneralProps[TPropKey]>)
|
|
408
410
|
}
|
|
409
411
|
}
|
|
410
412
|
return values
|
|
411
413
|
}
|
|
412
414
|
|
|
413
|
-
public static _getMergedMetaValue(causesProps:
|
|
415
|
+
public static _getMergedMetaValue(causesProps: Error0GeneralProps[]): Meta0.ValueType {
|
|
414
416
|
const metas = this._getFilledPropValues(causesProps, 'meta')
|
|
415
417
|
if (metas.length === 0) {
|
|
416
418
|
return {}
|
|
@@ -423,7 +425,7 @@ export class Error0 extends Error {
|
|
|
423
425
|
|
|
424
426
|
// stack
|
|
425
427
|
|
|
426
|
-
public static _removeConstructorStackPart(stack:
|
|
428
|
+
public static _removeConstructorStackPart(stack: Error0GeneralProps['stack']): Error0GeneralProps['stack'] {
|
|
427
429
|
if (!stack) {
|
|
428
430
|
return stack
|
|
429
431
|
}
|
|
@@ -439,9 +441,9 @@ export class Error0 extends Error {
|
|
|
439
441
|
}
|
|
440
442
|
|
|
441
443
|
public static _mergeStack(
|
|
442
|
-
prevStack:
|
|
443
|
-
nextStack:
|
|
444
|
-
):
|
|
444
|
+
prevStack: Error0GeneralProps['stack'],
|
|
445
|
+
nextStack: Error0GeneralProps['stack'],
|
|
446
|
+
): Error0GeneralProps['stack'] {
|
|
445
447
|
return [nextStack, prevStack].filter(Boolean).join('\n\n') || undefined
|
|
446
448
|
}
|
|
447
449
|
|
|
@@ -465,7 +467,7 @@ export class Error0 extends Error {
|
|
|
465
467
|
return false
|
|
466
468
|
}
|
|
467
469
|
|
|
468
|
-
public static _toError0(error: unknown, inputOverride:
|
|
470
|
+
public static _toError0(error: unknown, inputOverride: Error0Input = {}): Error0 {
|
|
469
471
|
if (error instanceof Error0) {
|
|
470
472
|
return error
|
|
471
473
|
}
|
|
@@ -498,16 +500,16 @@ export class Error0 extends Error {
|
|
|
498
500
|
return new Error0(this._getPropsFromUnknown(error, inputOverride))
|
|
499
501
|
}
|
|
500
502
|
|
|
501
|
-
static from(error: unknown, inputOverride?:
|
|
503
|
+
static from(error: unknown, inputOverride?: Error0Input): Error0 {
|
|
502
504
|
return this._toError0(error, inputOverride)
|
|
503
505
|
}
|
|
504
506
|
|
|
505
507
|
static extend(props: {
|
|
506
|
-
defaultMessage?:
|
|
507
|
-
defaultCode?:
|
|
508
|
-
defaultHttpStatus?:
|
|
509
|
-
defaultExpected?:
|
|
510
|
-
defaultClientMessage?:
|
|
508
|
+
defaultMessage?: Error0GeneralProps['message']
|
|
509
|
+
defaultCode?: Error0GeneralProps['code']
|
|
510
|
+
defaultHttpStatus?: Error0GeneralProps['httpStatus']
|
|
511
|
+
defaultExpected?: Error0GeneralProps['expected']
|
|
512
|
+
defaultClientMessage?: Error0GeneralProps['clientMessage']
|
|
511
513
|
defaultMeta?: Meta0.Meta0OrValueTypeNullish
|
|
512
514
|
}) {
|
|
513
515
|
const parent = this
|
|
@@ -517,18 +519,18 @@ export class Error0 extends Error {
|
|
|
517
519
|
static override defaultHttpStatus = props.defaultHttpStatus ?? parent.defaultHttpStatus
|
|
518
520
|
static override defaultExpected = props.defaultExpected ?? parent.defaultExpected
|
|
519
521
|
static override defaultClientMessage = props.defaultClientMessage ?? parent.defaultClientMessage
|
|
520
|
-
static override defaultMeta = Meta0.extend(
|
|
522
|
+
static override defaultMeta = Meta0.extend(props.defaultMeta, parent.defaultMeta)
|
|
521
523
|
}
|
|
522
524
|
}
|
|
523
525
|
|
|
524
526
|
static extendCollection<T extends Record<string, typeof Error0>>(
|
|
525
527
|
classes: T,
|
|
526
528
|
props: {
|
|
527
|
-
defaultMessage?:
|
|
528
|
-
defaultCode?:
|
|
529
|
-
defaultHttpStatus?:
|
|
530
|
-
defaultExpected?:
|
|
531
|
-
defaultClientMessage?:
|
|
529
|
+
defaultMessage?: Error0GeneralProps['message']
|
|
530
|
+
defaultCode?: Error0GeneralProps['code']
|
|
531
|
+
defaultHttpStatus?: Error0GeneralProps['httpStatus']
|
|
532
|
+
defaultExpected?: Error0GeneralProps['expected']
|
|
533
|
+
defaultClientMessage?: Error0GeneralProps['clientMessage']
|
|
532
534
|
defaultMeta?: Meta0.Meta0OrValueTypeNullish
|
|
533
535
|
},
|
|
534
536
|
): T {
|
|
@@ -550,7 +552,7 @@ export class Error0 extends Error {
|
|
|
550
552
|
__I_AM_ERROR_0: this.__I_AM_ERROR_0,
|
|
551
553
|
}
|
|
552
554
|
}
|
|
553
|
-
static toJSON(error: unknown, inputOverride?:
|
|
555
|
+
static toJSON(error: unknown, inputOverride?: Error0Input) {
|
|
554
556
|
const error0 = this.from(error, inputOverride)
|
|
555
557
|
return error0.toJSON()
|
|
556
558
|
}
|
|
@@ -570,38 +572,13 @@ export class Error0 extends Error {
|
|
|
570
572
|
}
|
|
571
573
|
|
|
572
574
|
export namespace Error0 {
|
|
573
|
-
export interface Input {
|
|
574
|
-
message?: string
|
|
575
|
-
tag?: string
|
|
576
|
-
code?: string
|
|
577
|
-
httpStatus?: HttpStatusCode | HttpStatusCodeString
|
|
578
|
-
expected?: boolean | Error0.ExpectedFn
|
|
579
|
-
clientMessage?: string
|
|
580
|
-
cause?: Error0Cause
|
|
581
|
-
stack?: string
|
|
582
|
-
meta?: Meta0.Meta0OrValueTypeNullish
|
|
583
|
-
zodError?: ZodError
|
|
584
|
-
axiosError?: AxiosError
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
export interface GeneralProps {
|
|
588
|
-
message: Input['message']
|
|
589
|
-
tag: Input['tag']
|
|
590
|
-
code: Input['code']
|
|
591
|
-
httpStatus: number | undefined
|
|
592
|
-
expected: boolean | undefined
|
|
593
|
-
clientMessage: Input['clientMessage']
|
|
594
|
-
anyMessage: string | undefined
|
|
595
|
-
cause: Input['cause']
|
|
596
|
-
stack: Error['stack']
|
|
597
|
-
meta: Meta0.ValueType
|
|
598
|
-
zodError?: ZodError
|
|
599
|
-
axiosError?: AxiosError
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
export type HttpStatusCodeString = keyof typeof HttpStatusCode
|
|
603
|
-
export type Error0Cause = Error | Error0 | unknown
|
|
604
|
-
export type ExpectedFn = (error: GeneralProps) => boolean | undefined
|
|
605
575
|
export type JSON = ReturnType<Error0['toJSON']>
|
|
606
576
|
export type Collection = Record<string, typeof Error0>
|
|
607
577
|
}
|
|
578
|
+
|
|
579
|
+
export const e0s = {
|
|
580
|
+
Default: Error0,
|
|
581
|
+
Expected: Error0.extend({
|
|
582
|
+
defaultExpected: true,
|
|
583
|
+
}) as typeof Error0,
|
|
584
|
+
} satisfies Error0.Collection
|