Commit a7305840 authored by Ad Schellevis's avatar Ad Schellevis

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

parent d0e7a795
......@@ -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'));
}
/**
......
......@@ -25,5 +25,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