From 6b8d9dc5d9f422cf85a83cb7a800110b53ed928b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 18 Jul 2018 09:29:12 +0300 Subject: [PATCH] Print an error on invalid request JSON When a request to the REST API is made with invalid JSON, it's hard to see why the request fails due to the fact that no error is sent. --- server/core/admin.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/core/admin.cc b/server/core/admin.cc index a8e14d1ed..266226b5c 100644 --- a/server/core/admin.cc +++ b/server/core/admin.cc @@ -106,8 +106,10 @@ int Client::process(string url, string method, const char* upload_data, size_t * if (m_data.length() && (json = json_loadb(m_data.c_str(), m_data.size(), 0, &err)) == NULL) { - MHD_Response *response = - MHD_create_response_from_buffer(0, NULL, MHD_RESPMEM_PERSISTENT); + string msg = string("{\"errors\": [ { \"detail\": \"Invalid JSON in request: ") + + err.text + "\" } ] }"; + MHD_Response *response = MHD_create_response_from_buffer(msg.size(), &msg[0], + MHD_RESPMEM_MUST_COPY); MHD_queue_response(m_connection, MHD_HTTP_BAD_REQUEST, response); MHD_destroy_response(response); return MHD_YES;