saleor-apps-redis_apl/apps/taxes/src/modules/app/webhook-response.ts
Adrian Pilarczyk 72adeb3b13
replace failureRetry/failureNoRetry webhook response with failure (#462)
* refactor: ♻️ replace failureRetry/failureNoRetry webhook response with failure

* build: 👷 add changeset

* refactor: ♻️ address feedback
2023-05-15 11:52:14 +02:00

25 lines
747 B
TypeScript

import { NextApiResponse } from "next";
import { createLogger, Logger } from "../../lib/logger";
/*
* idea: distinguish between async and sync webhooks
* when sync webhooks, require passing the event and enforce the required response format using ctx.buildResponse
* when async webhooks, dont require anything
*/
export class WebhookResponse {
private logger: Logger;
constructor(private res: NextApiResponse) {
this.logger = createLogger({ event: "WebhookResponse" });
}
failure(error: string) {
this.logger.debug({ error }, "failure called with:");
return this.res.status(500).json({ error });
}
success(data?: any) {
this.logger.debug({ data }, "success called with:");
return this.res.send(data);
}
}