fix middleware stuff
This commit is contained in:
@@ -47,19 +47,18 @@ app.use(express.static(path.join(__dirname, "public"), {
|
|||||||
app.use("/api/docs", swaggerUi.serve, swaggerUi.setup(specs));
|
app.use("/api/docs", swaggerUi.serve, swaggerUi.setup(specs));
|
||||||
app.use("/api", apiRouter);
|
app.use("/api", apiRouter);
|
||||||
|
|
||||||
app.use((req, res) => {
|
app.use((_req, res, next) => {
|
||||||
res.status(404).send("Not Found");
|
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
|
console.error(err);
|
||||||
app.use((_req, res, _next) => {
|
res.status(500).json({ status: "error", error: "Internal server error" });
|
||||||
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" });
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const server = https.createServer({
|
const server = https.createServer({
|
||||||
|
|||||||
Reference in New Issue
Block a user