fix(http): add malformed JSON syntax error handling middleware and update dist
CI / Build & Quality Check (push) Has been cancelled
CI / Build & Quality Check (push) Has been cancelled
This commit is contained in:
+12
@@ -48,6 +48,18 @@ function keysFromRequest(req: Request): EnvSource {
|
||||
const app = express();
|
||||
app.use(express.json({ limit: "1mb" }));
|
||||
|
||||
// Handle malformed JSON gracefully to prevent unhandled SyntaxErrors
|
||||
app.use((err: any, req: Request, res: Response, next: express.NextFunction) => {
|
||||
if (err instanceof SyntaxError && "body" in err) {
|
||||
return res.status(400).json({
|
||||
ok: false,
|
||||
error: "Bad Request",
|
||||
message: "Malformed JSON payload provided.",
|
||||
});
|
||||
}
|
||||
next(err);
|
||||
});
|
||||
|
||||
// Allow browser-based and cross-origin MCP clients.
|
||||
app.use((req, res, next) => {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
|
||||
Reference in New Issue
Block a user