Fix error logging
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
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
This commit is contained in:
+15
-5
@@ -37,7 +37,7 @@ function friendlyErrorMessage(statusCode) {
|
|||||||
|
|
||||||
async function reportError({ partofservice, error }) {
|
async function reportError({ partofservice, error }) {
|
||||||
try {
|
try {
|
||||||
await fetch(ERROR_LOG_API_URL, {
|
const response = await fetch(ERROR_LOG_API_URL, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -49,7 +49,12 @@ async function reportError({ partofservice, error }) {
|
|||||||
error,
|
error,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
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) {
|
function reportUnhandled(context, err) {
|
||||||
@@ -75,6 +80,11 @@ app.use((req, res, next) => {
|
|||||||
partofservice: `${req.method} ${req.originalUrl}`,
|
partofservice: `${req.method} ${req.originalUrl}`,
|
||||||
error: rawError,
|
error: rawError,
|
||||||
});
|
});
|
||||||
|
// /login errors are client-actionable: pass the specific message through
|
||||||
|
// instead of masking it with the generic session-expired text.
|
||||||
|
if (req.method === "POST" && req.path === "/login") {
|
||||||
|
return originalJson(body);
|
||||||
|
}
|
||||||
return originalJson({ error: friendlyErrorMessage(res.statusCode) });
|
return originalJson({ error: friendlyErrorMessage(res.statusCode) });
|
||||||
}
|
}
|
||||||
return originalJson(body);
|
return originalJson(body);
|
||||||
@@ -95,7 +105,7 @@ app.post("/login", async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const { userCode, password } = req.body;
|
const { userCode, password } = req.body;
|
||||||
if (!userCode || !password)
|
if (!userCode || !password)
|
||||||
return res.status(400).json({ error: "userCode and password required" });
|
return res.status(400).json({ error: "Vul gebruikerscode en wachtwoord in." });
|
||||||
|
|
||||||
const result = await db.query(
|
const result = await db.query(
|
||||||
"SELECT id, usercode, password FROM workers.users WHERE usercode = $1",
|
"SELECT id, usercode, password FROM workers.users WHERE usercode = $1",
|
||||||
@@ -104,13 +114,13 @@ app.post("/login", async (req, res) => {
|
|||||||
const user = result.rows[0];
|
const user = result.rows[0];
|
||||||
if (!user) {
|
if (!user) {
|
||||||
log("warn", "Login attempt for non-existent user", { userCode });
|
log("warn", "Login attempt for non-existent user", { userCode });
|
||||||
return res.status(401).json({ error: "invalid_credentials" });
|
return res.status(401).json({ error: "Ongeldige gebruikerscode of wachtwoord." });
|
||||||
}
|
}
|
||||||
|
|
||||||
const ok = await bcrypt.compare(password, user.password);
|
const ok = await bcrypt.compare(password, user.password);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
log("warn", "Invalid password for user", { userCode });
|
log("warn", "Invalid password for user", { userCode });
|
||||||
return res.status(401).json({ error: "invalid_credentials" });
|
return res.status(401).json({ error: "Ongeldige gebruikerscode of wachtwoord." });
|
||||||
}
|
}
|
||||||
|
|
||||||
const isAdmin = ADMIN_USER_CODES.has(Number(user.usercode));
|
const isAdmin = ADMIN_USER_CODES.has(Number(user.usercode));
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ function friendlyErrorMessage(statusCode) {
|
|||||||
|
|
||||||
async function reportError({ partofservice, error }) {
|
async function reportError({ partofservice, error }) {
|
||||||
try {
|
try {
|
||||||
await fetch(ERROR_LOG_API_URL, {
|
const response = await fetch(ERROR_LOG_API_URL, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -45,7 +45,12 @@ async function reportError({ partofservice, error }) {
|
|||||||
error,
|
error,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
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) {
|
function reportUnhandled(context, err) {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ function toFriendlyError(statusCode) {
|
|||||||
|
|
||||||
async function reportError({ partofservice, error }) {
|
async function reportError({ partofservice, error }) {
|
||||||
try {
|
try {
|
||||||
await fetch(ERROR_LOG_API_URL, {
|
const response = await fetch(ERROR_LOG_API_URL, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -74,7 +74,12 @@ async function reportError({ partofservice, error }) {
|
|||||||
error,
|
error,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
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) {
|
function reportUnhandled(context, err) {
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
const { ERROR_LOG_API_URL } = require("./env");
|
const { ERROR_LOG_API_URL } = require("./env");
|
||||||
|
const { log } = require("./log");
|
||||||
|
|
||||||
|
|
||||||
async function reportError({ partofservice, error }) {
|
async function reportError({ partofservice, error }) {
|
||||||
try {
|
try {
|
||||||
await fetch(ERROR_LOG_API_URL, {
|
const response = await fetch(ERROR_LOG_API_URL, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -15,7 +16,12 @@ async function reportError({ partofservice, error }) {
|
|||||||
error,
|
error,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
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 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user