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