Add req and res to onError callback for AsyncWebhook (#180)

This commit is contained in:
Lukasz Ostrowski 2023-02-15 11:08:09 +01:00 committed by GitHub
parent dffd4f5318
commit 4f9c9c2816
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View file

@ -160,14 +160,12 @@ describe("SaleorAsyncWebhook", () => {
*/ */
expect(res.statusCode).toBe(401); expect(res.statusCode).toBe(401);
expect(res._getData()).toBe("My Body"); 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(onErrorCallback).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
message: "Test error message", message: "Test error message",
}) }),
req,
res
); );
/** /**

View file

@ -20,7 +20,7 @@ interface WebhookManifestConfigurationBase {
asyncEvent: AsyncWebhookEventType; asyncEvent: AsyncWebhookEventType;
isActive?: boolean; isActive?: boolean;
apl: APL; apl: APL;
onError?(error: WebhookError | Error): void; onError?(error: WebhookError | Error, req: NextApiRequest, res: NextApiResponse): void;
formatErrorResponse?( formatErrorResponse?(
error: WebhookError | Error, error: WebhookError | Error,
req: NextApiRequest, req: NextApiRequest,
@ -163,7 +163,7 @@ export class SaleorAsyncWebhook<TPayload = unknown> {
debug(`Validation error: ${e.message}`); debug(`Validation error: ${e.message}`);
if (this.onError) { if (this.onError) {
this.onError(e); this.onError(e, req, res);
} }
if (this.formatErrorResponse) { if (this.formatErrorResponse) {
@ -185,7 +185,7 @@ export class SaleorAsyncWebhook<TPayload = unknown> {
debug("Unexpected error: %O", e); debug("Unexpected error: %O", e);
if (this.onError) { if (this.onError) {
this.onError(e); this.onError(e, req, res);
} }
if (this.formatErrorResponse) { if (this.formatErrorResponse) {