Skip to content

Commit

Permalink
fix: incoming errors were not correctly checked using instanceof
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzabuzaid committed May 18, 2022
1 parent f67f700 commit 4f230ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/problem_details_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export class ProblemDetailsOptions {
(context: HttpContext, error: any) => ProblemDetails
][] = [];

private rethrows: [Type<Error>, ((error: any) => boolean)?][] = [];

public includeExceptionDetails!: () => boolean;
public appendCacheHeaders!: (
setter: (name: string, value: string) => void
Expand Down Expand Up @@ -77,9 +79,7 @@ export class ProblemDetailsOptions {
error: TError
) {
const [, mapper] =
this.mappings.find(
([error]) => error instanceof (error.constructor as Type<TError>)
) ?? [];
this.mappings.find(([errorCtor]) => error instanceof errorCtor) ?? [];
// FIXME: should mapStatusCode exist at all? if there is no mapping for specific error then the default error
// handler should take control
return (
Expand All @@ -97,7 +97,13 @@ export class ProblemDetailsOptions {
})()
);
}
public rethrow() {}
public rethrow<TError extends Type<Error>>(
error: TError,
predicate?: (error: InstanceType<TError>) => boolean
) {
this.rethrows.push([error, predicate]);
}

public typePrefix?: string;
public contentTypes: string[] = [];
public exceptionDetailsPropertyName!: string;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["node_modules", "dist", "__test__"]
"exclude": ["node_modules", "dist", "__test__", "demo"]
}

0 comments on commit 4f230ed

Please sign in to comment.