mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-19 02:54:38 +00:00
(mvc, api) add error handling for api calls, https://github.com/opnsense/core/issues/1136
This commit is contained in:
parent
720acc9e1d
commit
9ed6406bdc
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user