Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure every route is caught by onError when using the provisioning API #465

Merged
merged 3 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

@justinbot justinbot Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting this will supersede any error handling implementation in the sublcass
e.g. https://github.com/matrix-org/matrix-appservice-irc/blob/develop/src/provisioning/Provisioner.ts#L144-L158

(Actually looking again I suppose it wouldn't since that wrapper goes before this error handler?)

I suppose the idea is you would now override onError instead?

Copy link
Contributor Author

@Half-Shot Half-Shot Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's certainly one way. Or you could wrap your handler in a try/catch and just not emit an error. The onError code was always intended to catch errors that fell through routes.

}

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