From 4f9c9c281628cadd0812d11d050da382476f036e Mon Sep 17 00:00:00 2001 From: Lukasz Ostrowski Date: Wed, 15 Feb 2023 11:08:09 +0100 Subject: [PATCH] Add req and res to onError callback for AsyncWebhook (#180) --- src/handlers/next/saleor-async-webhook.test.ts | 8 +++----- src/handlers/next/saleor-async-webhook.ts | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/handlers/next/saleor-async-webhook.test.ts b/src/handlers/next/saleor-async-webhook.test.ts index 74bfa66..961d33b 100644 --- a/src/handlers/next/saleor-async-webhook.test.ts +++ b/src/handlers/next/saleor-async-webhook.test.ts @@ -160,14 +160,12 @@ describe("SaleorAsyncWebhook", () => { */ expect(res.statusCode).toBe(401); expect(res._getData()).toBe("My Body"); - /** - * TODO This assertion fails, due to WebhookError constructor: - * [TypeError: Class constructor WebhookError cannot be invoked without 'new'] - */ expect(onErrorCallback).toHaveBeenCalledWith( expect.objectContaining({ message: "Test error message", - }) + }), + req, + res ); /** diff --git a/src/handlers/next/saleor-async-webhook.ts b/src/handlers/next/saleor-async-webhook.ts index 4d81ffe..e49be13 100644 --- a/src/handlers/next/saleor-async-webhook.ts +++ b/src/handlers/next/saleor-async-webhook.ts @@ -20,7 +20,7 @@ interface WebhookManifestConfigurationBase { asyncEvent: AsyncWebhookEventType; isActive?: boolean; apl: APL; - onError?(error: WebhookError | Error): void; + onError?(error: WebhookError | Error, req: NextApiRequest, res: NextApiResponse): void; formatErrorResponse?( error: WebhookError | Error, req: NextApiRequest, @@ -163,7 +163,7 @@ export class SaleorAsyncWebhook { debug(`Validation error: ${e.message}`); if (this.onError) { - this.onError(e); + this.onError(e, req, res); } if (this.formatErrorResponse) { @@ -185,7 +185,7 @@ export class SaleorAsyncWebhook { debug("Unexpected error: %O", e); if (this.onError) { - this.onError(e); + this.onError(e, req, res); } if (this.formatErrorResponse) {