Added HTTP response codes
This commit is contained in:
parent
db949dd361
commit
4202ae2ec7
1 changed files with 4 additions and 0 deletions
|
@ -19,10 +19,12 @@ final class Dispatcher
|
||||||
global $start;
|
global $start;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
$code = 200;
|
||||||
$json = $this->router->handle($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
|
$json = $this->router->handle($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
|
||||||
}
|
}
|
||||||
catch (\Exception $e)
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
|
$code = 400;
|
||||||
$json = [
|
$json = [
|
||||||
'error' => $e->getMessage(),
|
'error' => $e->getMessage(),
|
||||||
'trace' => $e->getTrace(),
|
'trace' => $e->getTrace(),
|
||||||
|
@ -30,6 +32,8 @@ final class Dispatcher
|
||||||
}
|
}
|
||||||
$end = microtime(true);
|
$end = microtime(true);
|
||||||
$json['__time'] = $end - $start;
|
$json['__time'] = $end - $start;
|
||||||
|
|
||||||
|
http_response_code($code);
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
echo json_encode($json);
|
echo json_encode($json);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue