diff --git a/src/Dispatcher.php b/src/Dispatcher.php index a9c2e1f2..0426d825 100644 --- a/src/Dispatcher.php +++ b/src/Dispatcher.php @@ -19,10 +19,12 @@ final class Dispatcher global $start; try { + $code = 200; $json = $this->router->handle($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']); } catch (\Exception $e) { + $code = 400; $json = [ 'error' => $e->getMessage(), 'trace' => $e->getTrace(), @@ -30,6 +32,8 @@ final class Dispatcher } $end = microtime(true); $json['__time'] = $end - $start; + + http_response_code($code); header('Content-Type: application/json'); echo json_encode($json); }