Skip to content

Commit

Permalink
Ensure every route is caught by onError when using the provisioning A…
Browse files Browse the repository at this point in the history
…PI (#465)

* Add an error handler after every route

* Ensure onError is protected

* changelog
  • Loading branch information
Half-Shot committed Apr 12, 2023
1 parent 7a9ff0b commit 8de1c2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/465.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure all routes added to ProvisioningApi are caught by onError.
7 changes: 4 additions & 3 deletions src/provisioning/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class ProvisioningApi {
path: string,
handler: (req: ProvisioningRequest, res: Response, next?: NextFunction) => void|Promise<void>,
fnName?: string): void {
this.baseRoute[method](path, async (req, res, next) => {
this.baseRoute[method](path, async (req: Express.Request, res: Response, next: NextFunction) => {
const expRequest = req as ExpRequestProvisioner;
const provisioningRequest = new ProvisioningRequest(
expRequest,
Expand All @@ -236,7 +236,8 @@ export class ProvisioningApi {
// Pass to error handler.
next([ex, provisioningRequest]);
}
});
// Always add an error handler
}, this.onError);
}

private async authenticateRequest(
Expand Down Expand Up @@ -403,7 +404,7 @@ export class ProvisioningApi {
}

// Needed so that _next can be defined in order to preserve signature.
private onError(
protected onError(
err: [IApiError|Error, ProvisioningRequest|Request]|IApiError|Error,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_req: Request, res: Response, _next: NextFunction) {
Expand Down

0 comments on commit 8de1c2e

Please sign in to comment.