Skip to content

Commit e7b1461

Browse files
committed
NO-TICKET support blacklist in getErrorMessage
1 parent 25f4dac commit e7b1461

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

index.node.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.web.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export declare type matcherKey = string | number | null;
2-
export declare const findKeyInObject: (obj: unknown, matcher: (key: matcherKey, value: unknown) => boolean, fallback?: unknown) => unknown;
2+
export declare const findKeyInObject: (obj: unknown, matcher: (key: matcherKey, value: unknown) => boolean, blacklistKeys: matcherKey[]) => unknown;
33
export declare class AdgoError extends Error {
44
code: string;
55
data: Record<string, unknown>;
@@ -8,4 +8,4 @@ export declare class AdgoError extends Error {
88
export declare class LocalError extends AdgoError {
99
constructor(error: AdgoError | Error | string, data?: Record<string, unknown>);
1010
}
11-
export declare const getErrorMessage: (error: unknown, fallbackMessage?: string, errorMessageKeys?: (string | number)[]) => unknown;
11+
export declare const getErrorMessage: (error: unknown, fallbackMessage?: string, errorMessageKeys?: (string | number)[], blacklistKeys?: matcherKey[]) => string;

src/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ export type matcherKey = string | number | null;
66
export const findKeyInObject = (
77
obj: unknown,
88
matcher: (key: matcherKey, value: unknown) => boolean,
9-
fallback: unknown | null = null,
9+
blacklistKeys: matcherKey[],
1010
) => {
11-
let result = fallback;
11+
let result: unknown = null;
1212

1313
const findValue = (key: matcherKey, value: unknown) => {
14-
if (result !== fallback) {
14+
if (result !== null) {
15+
return;
16+
}
17+
if (blacklistKeys.includes(key)) {
1518
return;
1619
}
1720

@@ -95,6 +98,7 @@ export const getErrorMessage = (
9598
'message',
9699
'error',
97100
],
101+
blacklistKeys: matcherKey[] = [],
98102
) => {
99103
if (isString(error)) {
100104
return error;
@@ -104,9 +108,10 @@ export const getErrorMessage = (
104108
const result = findKeyInObject(
105109
error,
106110
(k, v) => k === key && typeof v === 'string',
111+
blacklistKeys,
107112
);
108113
if (result) {
109-
return result;
114+
return result as string;
110115
}
111116
}
112117

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"suppressImplicitAnyIndexErrors": true,
88
"allowSyntheticDefaultImports": true,
99
"target": "es5",
10+
"lib": ["dom", "es7"],
1011
"declaration": true
1112
},
1213
"include": ["src/**/*"],

0 commit comments

Comments
 (0)