From da739e080fadb0dc2308b4d964102424f597eee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Nov=C3=BD?= Date: Sat, 22 Jan 2022 16:49:12 +0100 Subject: [PATCH] API: Detect wrong JSON and return correct error message --- application/controllers/Api.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 0993d809..0d6c3e51 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -421,7 +421,10 @@ class API extends CI_Controller { // Decode JSON and store $obj = json_decode(file_get_contents("php://input"), true); - + if ($obj === NULL) { + echo json_encode(['status' => 'failed', 'reason' => "wrong JSON"]); + die(); + } if(!isset($obj['key']) || $this->api_model->authorize($obj['key']) == 0) { http_response_code(401);