From a8162b57ba501f307080d597df9c6f9b7b63fd43 Mon Sep 17 00:00:00 2001 From: Lars Kiesow Date: Wed, 23 Nov 2022 02:15:36 +0100 Subject: [PATCH] Respond with bad request to unvalid request data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch updates the batch progress update endpoint to respond with a `400 Bad Request` instead of a `500 Internal Server Error` if a user sends an invalid request with no body. This is a user error after all. ``` ❯ curl -i -X PATCH \ 'http://127.0.0.1:3333/api/me/progress/batch/update' \ -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5Q_MoRptP0oI' \ -H 'Content-Type: application/json' HTTP/1.1 400 Bad Request … Missing request payload ``` --- server/controllers/MeController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/controllers/MeController.js b/server/controllers/MeController.js index 8a4848ee..f09a4b00 100644 --- a/server/controllers/MeController.js +++ b/server/controllers/MeController.js @@ -91,7 +91,7 @@ class MeController { async batchUpdateMediaProgress(req, res) { var itemProgressPayloads = req.body if (!itemProgressPayloads || !itemProgressPayloads.length) { - return res.sendStatus(500) + return res.status(400).send('Missing request payload') } var shouldUpdate = false