fix middleware stuff

This commit is contained in:
2025-09-12 13:45:05 +02:00
parent 03dbc5a82a
commit 066c2b4705

View File

@@ -47,19 +47,18 @@ app.use(express.static(path.join(__dirname, "public"), {
app.use("/api/docs", swaggerUi.serve, swaggerUi.setup(specs));
app.use("/api", apiRouter);
app.use((req, res) => {
res.status(404).send("Not Found");
})
app.use((_req, res, next) => {
if (res.error == null) {
return res.status(404).send("Not Found");
} else {
const err = res.error;
if (err instanceof ApiError) {
return res.status(err.status).json({ status: "error", error: err.message });
}
// has to be last
app.use((_req, res, _next) => {
const err = res.error;
if (err instanceof ApiError) {
return res.status(err.status).json({ status: "error", error: err.message });
console.error(err);
res.status(500).json({ status: "error", error: "Internal server error" });
}
console.error(err);
res.status(500).json({ status: "error", error: "Internal server error" });
})
const server = https.createServer({