summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-01-13 21:57:25 +0100
committerRory& <root@rory.gay>2026-01-13 21:57:25 +0100
commitdb8392264472cbcb2954517184ad3f74f8b096cf (patch)
tree5dd7e08679b4e5abd579e8cd7fbb855c1895a0aa
parentForgot to include assets (diff)
downloadserver-ts-db8392264472cbcb2954517184ad3f74f8b096cf.tar.xz
Include request info in errors
-rw-r--r--assets/openapi.json6
-rw-r--r--flake.nix1
-rw-r--r--src/api/Server.ts5
-rw-r--r--src/api/middlewares/ErrorHandler.ts4
4 files changed, 11 insertions, 5 deletions
diff --git a/assets/openapi.json b/assets/openapi.json

index c08c2810..78204ccb 100644 --- a/assets/openapi.json +++ b/assets/openapi.json
@@ -23561,6 +23561,12 @@ }, "tags": [ "auth" + ], + "x-badges": [ + { + "label": "Spacebar-only", + "color": "red" + } ] } }, diff --git a/flake.nix b/flake.nix
index c0fc2aa5..3f8cb421 100644 --- a/flake.nix +++ b/flake.nix
@@ -60,7 +60,6 @@ Cmd = [ "${self.outputs.packages.${system}.default}/bin/start-${mod}" ]; Expose = [ "3001" ]; }; - } ); }; diff --git a/src/api/Server.ts b/src/api/Server.ts
index f79e7dc5..7d0596a1 100644 --- a/src/api/Server.ts +++ b/src/api/Server.ts
@@ -97,8 +97,9 @@ export class SpacebarServer extends Server { // Emma [it/its] @ Rory& - the _ is required now, as pillarjs throw an error if you don't pass a param name now api.use("*_", (req: Request, res: Response) => { res.status(404).json({ - message: "404 endpoint not found", - code: 0, + message: "Endpoint not found", + code: 404, + request: `${req.method} ${req.url}`, }); }); diff --git a/src/api/middlewares/ErrorHandler.ts b/src/api/middlewares/ErrorHandler.ts
index 1a9a18a8..87e44c63 100644 --- a/src/api/middlewares/ErrorHandler.ts +++ b/src/api/middlewares/ErrorHandler.ts
@@ -61,9 +61,9 @@ export function ErrorHandler(error: Error & { type?: string }, req: Request, res if (httpcode > 511) httpcode = 400; - res.status(httpcode).json({ code: code, message, errors, _ajvErrors }); + res.status(httpcode).json({ code, message, errors, _ajvErrors, request: `${req.method} ${req.url}` }); } catch (error) { console.error(`[Internal Server Error] 500`, error); - return res.status(500).json({ code: 500, message: "Internal Server Error" }); + return res.status(500).json({ code: 500, message: `Internal server error while handling error`, request: `${req.method} ${req.url}` }); } }