Skip to content

Commit 21bcdc7

Browse files
committed
Add error handling for JSON.parse
Resolves #73
1 parent e541281 commit 21bcdc7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ app.all('*', (req, res) => {
105105

106106
//If the Content-Type of the incoming body `is` JSON, it can be parsed and returned in the body
107107
if(req.is('application/json')){
108-
echo.json = JSON.parse(req.body)
108+
try {
109+
echo.json = JSON.parse(req.body)
110+
} catch (error) {
111+
console.warn("Invalid JSON Body received with Content-Type: application/json", error);
112+
}
109113
}
110114

111115
//If there's a JWT header, parse it and decode and put it in the response

0 commit comments

Comments
 (0)