diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Base/ApiControllerBase.php b/src/opnsense/mvc/app/controllers/OPNsense/Base/ApiControllerBase.php index f5b0d504f..238fdf970 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Base/ApiControllerBase.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Base/ApiControllerBase.php @@ -137,23 +137,23 @@ class ApiControllerBase extends ControllerRoot $req_c = $object_info->getMethod($callMethodName)->getNumberOfRequiredParameters(); if ($req_c > count($dispatcher->getParams())) { $dispatchError = 'action ' . $dispatcher->getActionName() . - ' expects at least '. $req_c . ' parameter(s)'; - } else { - // if body is send as json data, parse to $_POST first - $dispatchError = $this->parseJsonBodyData(); - } - if ($dispatchError != null) { - // send error to client - $this->response->setStatusCode(400, "Bad Request"); - $this->response->setContentType('application/json', 'UTF-8'); - $this->response->setJsonContent( - array('message' => $dispatchError, - 'status' => 400) - ); - $this->response->send(); - return false; + ' expects at least ' . $req_c . ' parameter(s)'; } } + // if body is send as json data, parse to $_POST first + $dispatchError = empty($dispatchError) ? $this->parseJsonBodyData() : $dispatchError; + + if ($dispatchError != null) { + // send error to client + $this->response->setStatusCode(400, "Bad Request"); + $this->response->setContentType('application/json', 'UTF-8'); + $this->response->setJsonContent( + array('message' => $dispatchError, + 'status' => 400) + ); + $this->response->send(); + return false; + } return true; }