@deliverart/sdk-js-error-handler 0.0.7 → 0.0.8
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/CHANGELOG.md +6 -0
- package/dist/index.cjs +14 -0
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +12 -0
- package/package.json +1 -1
- package/src/form-state.ts +11 -0
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,8 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
ApiError: () => ApiError,
|
|
24
24
|
ErrorHandlerPlugin: () => ErrorHandlerPlugin,
|
|
25
|
+
FormStateError: () => FormStateError,
|
|
26
|
+
formStateErrorToThrowable: () => formStateErrorToThrowable,
|
|
25
27
|
throwableToFormState: () => throwableToFormState,
|
|
26
28
|
validationErrorDataSchema: () => validationErrorDataSchema
|
|
27
29
|
});
|
|
@@ -33,6 +35,16 @@ var ApiError = class extends import_axios.AxiosError {
|
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
// src/form-state.ts
|
|
38
|
+
var FormStateError = class extends Error {
|
|
39
|
+
constructor(error) {
|
|
40
|
+
super(error.type === "VALIDATION_ERROR" ? "Validation error" : "Unknown error");
|
|
41
|
+
this.error = error;
|
|
42
|
+
this.name = "FormStateError";
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
function formStateErrorToThrowable(error) {
|
|
46
|
+
return new FormStateError(error);
|
|
47
|
+
}
|
|
36
48
|
async function throwableToFormState(fn) {
|
|
37
49
|
try {
|
|
38
50
|
const data = await fn();
|
|
@@ -107,6 +119,8 @@ var ErrorHandlerPlugin = class {
|
|
|
107
119
|
0 && (module.exports = {
|
|
108
120
|
ApiError,
|
|
109
121
|
ErrorHandlerPlugin,
|
|
122
|
+
FormStateError,
|
|
123
|
+
formStateErrorToThrowable,
|
|
110
124
|
throwableToFormState,
|
|
111
125
|
validationErrorDataSchema
|
|
112
126
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -60,10 +60,15 @@ type FormState<T> = {
|
|
|
60
60
|
success: false;
|
|
61
61
|
error: ApiErrorData;
|
|
62
62
|
};
|
|
63
|
+
declare class FormStateError extends Error {
|
|
64
|
+
readonly error: ApiErrorData;
|
|
65
|
+
constructor(error: ApiErrorData);
|
|
66
|
+
}
|
|
67
|
+
declare function formStateErrorToThrowable(error: ApiErrorData): FormStateError;
|
|
63
68
|
declare function throwableToFormState<T>(fn: () => Promise<T>): Promise<FormState<T>>;
|
|
64
69
|
|
|
65
70
|
declare class ErrorHandlerPlugin implements ApiClientPlugin<{}> {
|
|
66
71
|
setup(client: ApiClient): {};
|
|
67
72
|
}
|
|
68
73
|
|
|
69
|
-
export { ApiError, type ApiErrorData, ErrorHandlerPlugin, type FormState, type ValidationErrorData, throwableToFormState, validationErrorDataSchema };
|
|
74
|
+
export { ApiError, type ApiErrorData, ErrorHandlerPlugin, type FormState, FormStateError, type ValidationErrorData, formStateErrorToThrowable, throwableToFormState, validationErrorDataSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -60,10 +60,15 @@ type FormState<T> = {
|
|
|
60
60
|
success: false;
|
|
61
61
|
error: ApiErrorData;
|
|
62
62
|
};
|
|
63
|
+
declare class FormStateError extends Error {
|
|
64
|
+
readonly error: ApiErrorData;
|
|
65
|
+
constructor(error: ApiErrorData);
|
|
66
|
+
}
|
|
67
|
+
declare function formStateErrorToThrowable(error: ApiErrorData): FormStateError;
|
|
63
68
|
declare function throwableToFormState<T>(fn: () => Promise<T>): Promise<FormState<T>>;
|
|
64
69
|
|
|
65
70
|
declare class ErrorHandlerPlugin implements ApiClientPlugin<{}> {
|
|
66
71
|
setup(client: ApiClient): {};
|
|
67
72
|
}
|
|
68
73
|
|
|
69
|
-
export { ApiError, type ApiErrorData, ErrorHandlerPlugin, type FormState, type ValidationErrorData, throwableToFormState, validationErrorDataSchema };
|
|
74
|
+
export { ApiError, type ApiErrorData, ErrorHandlerPlugin, type FormState, FormStateError, type ValidationErrorData, formStateErrorToThrowable, throwableToFormState, validationErrorDataSchema };
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,16 @@ var ApiError = class extends AxiosError {
|
|
|
4
4
|
};
|
|
5
5
|
|
|
6
6
|
// src/form-state.ts
|
|
7
|
+
var FormStateError = class extends Error {
|
|
8
|
+
constructor(error) {
|
|
9
|
+
super(error.type === "VALIDATION_ERROR" ? "Validation error" : "Unknown error");
|
|
10
|
+
this.error = error;
|
|
11
|
+
this.name = "FormStateError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
function formStateErrorToThrowable(error) {
|
|
15
|
+
return new FormStateError(error);
|
|
16
|
+
}
|
|
7
17
|
async function throwableToFormState(fn) {
|
|
8
18
|
try {
|
|
9
19
|
const data = await fn();
|
|
@@ -77,6 +87,8 @@ var ErrorHandlerPlugin = class {
|
|
|
77
87
|
export {
|
|
78
88
|
ApiError,
|
|
79
89
|
ErrorHandlerPlugin,
|
|
90
|
+
FormStateError,
|
|
91
|
+
formStateErrorToThrowable,
|
|
80
92
|
throwableToFormState,
|
|
81
93
|
validationErrorDataSchema
|
|
82
94
|
};
|
package/package.json
CHANGED
package/src/form-state.ts
CHANGED
|
@@ -10,6 +10,17 @@ export type FormState<T> =
|
|
|
10
10
|
error: ApiErrorData
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export class FormStateError extends Error {
|
|
14
|
+
constructor(public readonly error: ApiErrorData) {
|
|
15
|
+
super(error.type === 'VALIDATION_ERROR' ? 'Validation error' : 'Unknown error')
|
|
16
|
+
this.name = 'FormStateError'
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function formStateErrorToThrowable(error: ApiErrorData): FormStateError {
|
|
21
|
+
return new FormStateError(error)
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
export async function throwableToFormState<T>(fn: () => Promise<T>): Promise<FormState<T>> {
|
|
14
25
|
try {
|
|
15
26
|
const data = await fn()
|