From 1136c0d7af9d78c36478fcad17b0703972923056 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 4 Nov 2025 11:12:29 +0000 Subject: [PATCH 1/2] Initial plan From a23a163bfa3307f5233dd288ab5c66364e390c06 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 4 Nov 2025 11:19:23 +0000 Subject: [PATCH 2/2] Fix authentication error handling to return JSON for API requests Co-authored-by: CuteMurasame <88932464+CuteMurasame@users.noreply.github.com> --- middleware/error_display.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/middleware/error_display.js b/middleware/error_display.js index 0a06861..618b37a 100644 --- a/middleware/error_display.js +++ b/middleware/error_display.js @@ -1,3 +1,16 @@ +import { makeResponse } from "../core/utils.js"; + export default (err, req, res, next) => { + // Check if this is an API/JSON request + const isJsonRequest = req.path.startsWith('/api/') || + req.xhr || + req.headers.accept?.includes('application/json'); + + if (isJsonRequest) { + // Return JSON error response + return res.json(makeResponse(false, { message: err.message })); + } + + // Return HTML error page for regular requests res.render('system/error.njk', { title: "错误", error_message: err.message }); } \ No newline at end of file