yummies 4.2.0 → 4.2.1
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/errors.d.ts +8 -8
- package/errors.d.ts.map +1 -1
- package/errors.js +12 -12
- package/package.json +1 -1
package/errors.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Maybe } from './utils/types.js';
|
|
2
|
-
type
|
|
3
|
-
type
|
|
2
|
+
type GetErrorTextEnhancer = (error: any) => string;
|
|
3
|
+
type GetErrorTextFormatErrorFn = (error: Error) => string;
|
|
4
4
|
/**
|
|
5
5
|
* Universal function for transforming any errors into readable error text
|
|
6
6
|
*
|
|
7
7
|
* This function can be enhanced with custom handlers using:
|
|
8
|
-
* - `
|
|
9
|
-
* - `
|
|
10
|
-
* - `
|
|
8
|
+
* - `getErrorText.unknownErrorText`
|
|
9
|
+
* - `getErrorText.formatError`
|
|
10
|
+
* - `getErrorText.enhance`
|
|
11
11
|
*/
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const getErrorText: {
|
|
13
13
|
(error: unknown): string;
|
|
14
14
|
unknownErrorText: string;
|
|
15
|
-
formatError: Maybe<
|
|
16
|
-
enhance: Maybe<
|
|
15
|
+
formatError: Maybe<GetErrorTextFormatErrorFn>;
|
|
16
|
+
enhance: Maybe<GetErrorTextEnhancer>;
|
|
17
17
|
};
|
|
18
18
|
export {};
|
|
19
19
|
//# sourceMappingURL=errors.d.ts.map
|
package/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,KAAK,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,CAAC;AACnD,KAAK,yBAAyB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC;AAE1D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY;YAAW,OAAO;;;;CAkB1C,CAAC"}
|
package/errors.js
CHANGED
|
@@ -3,27 +3,27 @@ import { typeGuard } from './type-guard/index.js';
|
|
|
3
3
|
* Universal function for transforming any errors into readable error text
|
|
4
4
|
*
|
|
5
5
|
* This function can be enhanced with custom handlers using:
|
|
6
|
-
* - `
|
|
7
|
-
* - `
|
|
8
|
-
* - `
|
|
6
|
+
* - `getErrorText.unknownErrorText`
|
|
7
|
+
* - `getErrorText.formatError`
|
|
8
|
+
* - `getErrorText.enhance`
|
|
9
9
|
*/
|
|
10
|
-
export const
|
|
10
|
+
export const getErrorText = (error) => {
|
|
11
11
|
if (!error) {
|
|
12
|
-
return
|
|
12
|
+
return getErrorText.unknownErrorText;
|
|
13
13
|
}
|
|
14
14
|
if (typeGuard.isString(error)) {
|
|
15
15
|
return error;
|
|
16
16
|
}
|
|
17
17
|
if (error instanceof Error) {
|
|
18
|
-
return
|
|
18
|
+
return getErrorText.formatError?.(error) ?? error.message;
|
|
19
19
|
}
|
|
20
|
-
if (
|
|
21
|
-
return
|
|
20
|
+
if (getErrorText.enhance) {
|
|
21
|
+
return getErrorText.enhance(error);
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
return
|
|
24
|
+
return getErrorText.unknownErrorText;
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
getErrorText.unknownErrorText = '';
|
|
28
|
+
getErrorText.formatError = null;
|
|
29
|
+
getErrorText.enhance = null;
|