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