API: Detect wrong JSON and return correct error message

pull/1383/head
Ondřej Nový 2022-01-22 16:49:12 +01:00 zatwierdzone przez Peter Goodhall
rodzic 96d7a2537d
commit da739e080f
1 zmienionych plików z 4 dodań i 1 usunięć

Wyświetl plik

@ -421,7 +421,10 @@ class API extends CI_Controller {
// Decode JSON and store // Decode JSON and store
$obj = json_decode(file_get_contents("php://input"), true); $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) { if(!isset($obj['key']) || $this->api_model->authorize($obj['key']) == 0) {
http_response_code(401); http_response_code(401);