mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-08 11:52:55 +01:00
Fix body-parser errors not being filtered in ErrorHandler middleware
This commit is contained in:
parent
174d34c376
commit
164fcc25f3
@ -1,5 +1,5 @@
|
||||
diff --git a/node_modules/body-parser/lib/types/json.js b/node_modules/body-parser/lib/types/json.js
|
||||
index c2745be..7104cfa 100644
|
||||
index c2745be..17c2cfe 100644
|
||||
--- a/node_modules/body-parser/lib/types/json.js
|
||||
+++ b/node_modules/body-parser/lib/types/json.js
|
||||
@@ -18,6 +18,7 @@ var createError = require('http-errors')
|
||||
@ -28,3 +28,12 @@ index c2745be..7104cfa 100644
|
||||
} catch (e) {
|
||||
return normalizeJsonSyntaxError(e, {
|
||||
message: e.message.replace('#', char),
|
||||
@@ -216,7 +217,7 @@ function normalizeJsonSyntaxError (error, obj) {
|
||||
}
|
||||
|
||||
// replace stack before message for Node.js 0.10 and below
|
||||
- error.stack = obj.stack.replace(error.message, obj.message)
|
||||
+ error.stack = obj.stack?.replace(error.message, obj.message)
|
||||
error.message = obj.message
|
||||
|
||||
return error
|
||||
|
@ -22,7 +22,7 @@ import { ApiError, FieldError } from "@spacebar/util";
|
||||
const EntityNotFoundErrorRegex = /"(\w+)"/;
|
||||
|
||||
export function ErrorHandler(
|
||||
error: Error,
|
||||
error: Error & { type?: string },
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction,
|
||||
@ -50,6 +50,11 @@ export function ErrorHandler(
|
||||
code = Number(error.code);
|
||||
message = error.message;
|
||||
errors = error.errors;
|
||||
} else if (error?.type == "entity.parse.failed") {
|
||||
// body-parser failed
|
||||
httpcode = 400;
|
||||
code = 50109;
|
||||
message = "The request body contains invalid JSON.";
|
||||
} else {
|
||||
console.error(
|
||||
`[Error] ${code} ${req.url}\n`,
|
||||
|
Loading…
Reference in New Issue
Block a user