Improve debug messages for async webhook handler (#105)
This commit is contained in:
parent
7abad6a3d8
commit
33d7666c7d
1 changed files with 6 additions and 3 deletions
|
@ -117,22 +117,25 @@ export class SaleorAsyncWebhook<TPayload = unknown> {
|
||||||
*/
|
*/
|
||||||
createHandler(handlerFn: NextWebhookApiHandler<TPayload>): NextApiHandler {
|
createHandler(handlerFn: NextWebhookApiHandler<TPayload>): NextApiHandler {
|
||||||
return async (req, res) => {
|
return async (req, res) => {
|
||||||
|
debug(`Handler for webhook ${this.name} called`);
|
||||||
await processAsyncSaleorWebhook<TPayload>({
|
await processAsyncSaleorWebhook<TPayload>({
|
||||||
req,
|
req,
|
||||||
apl: this.apl,
|
apl: this.apl,
|
||||||
allowedEvent: this.asyncEvent,
|
allowedEvent: this.asyncEvent,
|
||||||
})
|
})
|
||||||
.then(async (context) => {
|
.then(async (context) => {
|
||||||
debug("Call handlerFn");
|
debug("Incoming request validated. Call handlerFn");
|
||||||
return handlerFn(req, res, context);
|
return handlerFn(req, res, context);
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
|
debug(`Unexpected error during processing the webhook ${this.name}`);
|
||||||
|
|
||||||
if (e instanceof WebhookError) {
|
if (e instanceof WebhookError) {
|
||||||
debug(e.message);
|
debug(`Validation error: ${e.message}`);
|
||||||
res.status(ErrorCodeMap[e.errorType] || 400).end();
|
res.status(ErrorCodeMap[e.errorType] || 400).end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
debug("Unexpected error during processing the webhook %O", e);
|
debug("Unexpected error: %O", e);
|
||||||
res.status(500).end();
|
res.status(500).end();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue