Refactored all api endpoints to /bus/xxxxx
Build and Push Docker Images / detect-changes (push) Successful in 20s
Build and Push Docker Images / build-auth-api (push) Successful in 2m2s
Build and Push Docker Images / build-employee-api (push) Successful in 2m2s
Build and Push Docker Images / build-transit-api (push) Successful in 2m8s
Build and Push Docker Images / build-error-log-api (push) Successful in 1m58s
Build and Push Docker Images / build-monitoring-ui (push) Has been cancelled
Build and Push Docker Images / build-admin-ui (push) Has been cancelled
Build and Push Docker Images / deploy-test-node (push) Has been cancelled
Build and Push Docker Images / detect-changes (push) Successful in 20s
Build and Push Docker Images / build-auth-api (push) Successful in 2m2s
Build and Push Docker Images / build-employee-api (push) Successful in 2m2s
Build and Push Docker Images / build-transit-api (push) Successful in 2m8s
Build and Push Docker Images / build-error-log-api (push) Successful in 1m58s
Build and Push Docker Images / build-monitoring-ui (push) Has been cancelled
Build and Push Docker Images / build-admin-ui (push) Has been cancelled
Build and Push Docker Images / deploy-test-node (push) Has been cancelled
This commit is contained in:
+20
-1
@@ -15,7 +15,26 @@ pool.query('SELECT 1')
|
||||
.catch(err => {
|
||||
console.error('PostgreSQL connection FAILED');
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
const url = process.env.ERROR_LOG_API_URL || 'https://error.xtransit.testinstance.nl/error_log';
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), 5000);
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-internal-api-key': process.env.INTERNAL_API_KEY || '',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
service: 'employee_api',
|
||||
partofservice: 'startup: db connection',
|
||||
error: err.stack || err.message || String(err),
|
||||
}),
|
||||
signal: controller.signal,
|
||||
}).catch(() => {})
|
||||
.finally(() => {
|
||||
clearTimeout(timer);
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
|
||||
+13
-1
@@ -48,12 +48,24 @@ async function reportError({ partofservice, error }) {
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
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 });
|
||||
}
|
||||
|
||||
process.on("uncaughtException", (err) => reportUnhandled("uncaughtException", err));
|
||||
process.on("unhandledRejection", (reason) => reportUnhandled("unhandledRejection", reason));
|
||||
|
||||
app.use((req, res, next) => {
|
||||
const originalJson = res.json.bind(res);
|
||||
res.json = (body) => {
|
||||
if (res.statusCode >= 400 && body && typeof body === "object") {
|
||||
const rawError =
|
||||
body.error || body.message || body.details || `HTTP ${res.statusCode}`;
|
||||
[body.error, body.message, body.details]
|
||||
.filter((v) => v !== undefined && v !== null && v !== "")
|
||||
.join(" - ") || `HTTP ${res.statusCode}`;
|
||||
log("warn", `HTTP ${res.statusCode}`, { path: req.originalUrl, method: req.method, error: rawError });
|
||||
void reportError({
|
||||
partofservice: `${req.method} ${req.originalUrl}`,
|
||||
|
||||
Reference in New Issue
Block a user