added excetion handler around RequestController
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
36e376337e
commit
b9401769bc
|
@ -1,6 +1,9 @@
|
||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
error_reporting(error_level: E_ALL);
|
error_reporting(error_level: E_ALL);
|
||||||
|
|
||||||
require dirname(path: __DIR__) . '/vendor/autoload.php';
|
require dirname(path: __DIR__) . '/vendor/autoload.php';
|
||||||
|
@ -19,7 +22,6 @@ header(header: "Access-Control-Max-Age: 3600");
|
||||||
header(header: "Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
header(header: "Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO make a log class
|
// TODO make a log class
|
||||||
$oFile = fopen(filename: 'log.txt', mode: 'a');
|
$oFile = fopen(filename: 'log.txt', mode: 'a');
|
||||||
|
|
||||||
|
@ -35,6 +37,13 @@ if ($uri[1] !== 'api') {
|
||||||
|
|
||||||
$requestMethod = $_SERVER["REQUEST_METHOD"];
|
$requestMethod = $_SERVER["REQUEST_METHOD"];
|
||||||
|
|
||||||
|
try {
|
||||||
$controller = new RequestController(config: $config, requestMethod: $requestMethod, uri: $uri);
|
$controller = new RequestController(config: $config, requestMethod: $requestMethod, uri: $uri);
|
||||||
$controller->processRequest();
|
$controller->processRequest();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo json_encode(value: [
|
||||||
|
'error' => $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue