Commit 9ed6406b authored by Ad Schellevis's avatar Ad Schellevis

(mvc, api) add error handling for api calls, https://github.com/opnsense/core/issues/1136

parent 720acc9e
......@@ -57,6 +57,17 @@ class ApiControllerBase extends ControllerRoot
return null;
}
/**
* Raise errors, warnings, notices, etc.
* @param $errno
* @param $errstr
* @throws \Exception
*/
public function APIErrorHandler($errno, $errstr)
{
throw new \Exception($errstr . ' ['.$errno.']');
}
/**
* Initialize API controller
*/
......@@ -64,6 +75,7 @@ class ApiControllerBase extends ControllerRoot
{
// disable view processing
$this->view->disable();
set_error_handler(array($this, 'APIErrorHandler'));
}
/**
......
......@@ -26,5 +26,9 @@ try {
echo $application->handle()->getContent();
} catch (\Exception $e) {
echo $e->getMessage();
$response = array();
$response['errorMessage'] = $e->getMessage();
header("Content-Type: application/json;charset=utf-8");
echo htmlspecialchars(json_encode($response), ENT_NOQUOTES);
error_log($e);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment