Add req and res to onError callback for AsyncWebhook (#180)
This commit is contained in:
parent
dffd4f5318
commit
4f9c9c2816
2 changed files with 6 additions and 8 deletions
|
@ -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
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<TPayload = unknown> {
|
|||
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<TPayload = unknown> {
|
|||
debug("Unexpected error: %O", e);
|
||||
|
||||
if (this.onError) {
|
||||
this.onError(e);
|
||||
this.onError(e, req, res);
|
||||
}
|
||||
|
||||
if (this.formatErrorResponse) {
|
||||
|
|
Loading…
Reference in a new issue