Files
The-transit-Project/transit_api/lib/report-error.js
T
Sven laptop 30f4ca6701
Build and Push Docker Images / detect-changes (push) Successful in 23s
Build and Push Docker Images / build-employee-api (push) Successful in 2m20s
Build and Push Docker Images / build-auth-api (push) Successful in 3m27s
Build and Push Docker Images / build-transit-api (push) Successful in 3m4s
Build and Push Docker Images / build-error-log-api (push) Successful in 2m38s
Build and Push Docker Images / build-admin-ui (push) Successful in 3m48s
Build and Push Docker Images / build-monitoring-ui (push) Successful in 3m45s
Build and Push Docker Images / deploy-test-node (push) Successful in 9s
Fix error logging
2026-09-25 00:02:14 +02:00

36 lines
1002 B
JavaScript

const { ERROR_LOG_API_URL } = require("./env");
const { log } = require("./log");
async function reportError({ partofservice, error }) {
try {
const response = await fetch(ERROR_LOG_API_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-internal-api-key": process.env.INTERNAL_API_KEY || "",
},
body: JSON.stringify({
service: "transit_api",
partofservice,
error,
}),
});
if (!response.ok) {
log("warn", "Error log forward failed", { status: response.status, partofservice });
}
} catch (err) {
log("warn", "Error log forward failed", { error: err.message, partofservice });
}
}
function reportUnhandled(context, err) {
const message = err?.message || String(err);
const stack = err?.stack || message;
log("error", context, { error: message, stack });
void reportError({ partofservice: context, error: stack });
}
module.exports = { reportError, reportUnhandled };