Skip to content

Commit

Permalink
Merge pull request #1 from lukas-reineke/no-ticket-data
Browse files Browse the repository at this point in the history
NO-TICKET use data to store additional values
  • Loading branch information
rmcauley authored Feb 18, 2020
2 parents 71c9ed3 + eff86c7 commit 7e80500
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion index.node.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.web.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export declare type matcherKey = string | number | null;
export declare const findKeyInObject: (obj: unknown, matcher: (key: matcherKey, value: unknown) => boolean, fallback?: unknown) => unknown;
export declare class AdgoError extends Error {
code: string;
data: Record<string, unknown>;
constructor(error: AdgoError | Error | string, data?: Record<string, unknown>, code?: string);
}
export declare class LocalError extends AdgoError {
Expand Down
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const findKeyInObject = (

export class AdgoError extends Error {
code: string;
data: Record<string, unknown>;

constructor(
error: AdgoError | Error | string,
Expand All @@ -61,14 +62,11 @@ export class AdgoError extends Error {

this.code = (error as AdgoError).code || (data.code as string) || code;
this.name = (error as AdgoError).name || 'AdgoError';
this.data = { ...(error as AdgoError).data, ...data };

if ((error as AdgoError).stack) {
this.stack = (error as AdgoError).stack;
}

for (const key of Object.keys(data)) {
this[key] = data[key];
}
}
}

Expand Down

0 comments on commit 7e80500

Please sign in to comment.