Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ app.all('*', (req, res) => {

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

//If there's a JWT header, parse it and decode and put it in the response
Expand Down
9 changes: 9 additions & 0 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ else
exit 1
fi

REQUEST=$(curl -s -X POST -H "Content-Type: application/json" -d 'not-json' http://localhost:8080)
if [ $(echo $REQUEST | jq -r '.json') == 'null' ]; then
passed "JSON with Invalid Body test passed."
else
failed "JSON with Invalid Body test failed."
echo $REQUEST | jq
exit 1
fi

message " Stop containers "
docker stop http-echo-tests
sleep 5
Expand Down