Skip to content

Commit 0abd010

Browse files
committed
fixing: the 502 error when calling prod API
1 parent b90cbd3 commit 0abd010

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

backend/src/lib/logger.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pino from "pino";
22
import pinoHttp from "pino-http";
3+
import crypto from "node:crypto";
34

45
// Fields that must never appear in plain-text logs
56
const REDACTED_PATHS = [

backend/src/routes/payments.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ function createPaymentsRouter({
214214
async function createSession(req, res, next) {
215215
try {
216216
const body = req.body;
217+
logger.info({ merchantId: req.merchant?.id, amount: body.amount, asset: body.asset }, "DEBUG: createSession started");
217218

218219
// Per-asset payment limit validation (#153)
219220
const limits = req.merchant.payment_limits;
@@ -303,6 +304,7 @@ function createPaymentsRouter({
303304
paymentCreatedCounter.inc({ asset: body.asset });
304305
}
305306

307+
logger.info({ paymentId: paymentId }, "DEBUG: createSession success");
306308
res.status(201).json({
307309
payment_id: paymentId,
308310
payment_link: paymentLink,
@@ -311,6 +313,7 @@ function createPaymentsRouter({
311313
branding_config: resolvedBrandingConfig,
312314
});
313315
} catch (err) {
316+
logger.error({ err, merchantId: req.merchant?.id }, "DEBUG: createSession error");
314317
if (err.status === 400 && err.details) {
315318
return res.status(400).json({ error: err.message, ...err.details });
316319
}

backend/src/server.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ async function startServer() {
102102

103103
process.on("SIGTERM", () => shutdown("SIGTERM"));
104104
process.on("SIGINT", () => shutdown("SIGINT"));
105+
106+
process.on("uncaughtException", (err) => {
107+
logger.fatal({ err }, "UNCAUGHT_EXCEPTION: process crashing");
108+
// Allow logger to flush before exiting
109+
setTimeout(() => process.exit(1), 1000);
110+
});
111+
112+
process.on("unhandledRejection", (reason, promise) => {
113+
logger.error({ reason, promise }, "UNHANDLED_REJECTION: a promise was rejected but not caught");
114+
});
105115
}
106116

107117
startServer();

0 commit comments

Comments
 (0)