mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-13 16:14:40 +00:00
38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
|
|
function error_output($http_code, $e, $user_message)
|
|
{
|
|
$response = [];
|
|
if (!file_exists('/var/run/development')) {
|
|
$response['errorMessage'] = $user_message;
|
|
} else {
|
|
$response['errorMessage'] = $e->getMessage();
|
|
$response['errorTrace'] = $e->getTraceAsString();
|
|
}
|
|
if (method_exists($e, 'getTitle')) {
|
|
$response['errorTitle'] = $e->getTitle();
|
|
}
|
|
header('HTTP', true, $http_code);
|
|
header("Content-Type: application/json;charset=utf-8");
|
|
echo json_encode($response, JSON_UNESCAPED_SLASHES);
|
|
}
|
|
|
|
|
|
try {
|
|
$config = include __DIR__ . "/../mvc/app/config/config.php";
|
|
include __DIR__ . "/../mvc/app/config/loader.php";
|
|
|
|
$router = new OPNsense\Mvc\Router('/api/', 'Api');
|
|
$response = $router->routeRequest($_SERVER['REQUEST_URI']);
|
|
if (!$response->isSent()) {
|
|
$response->send();
|
|
}
|
|
} catch (\OPNsense\Base\UserException $e) {
|
|
error_output(500, $e, $e->getMessage());
|
|
} catch (\OPNsense\Mvc\Exceptions\DispatchException) {
|
|
error_output(404, $e, gettext('Endpoint not found'));
|
|
} catch (\Error | \Exception $e) {
|
|
error_output(500, $e, gettext('Unexpected error, check log for details'));
|
|
error_log($e);
|
|
}
|