Api exeption handler
This commit is contained in:
parent
8300e47b76
commit
119149bf5e
@ -36,9 +36,12 @@ Autoloader::setRoot('/var/www/dev.steelants.cz/vasek/home-update/');
|
||||
class ErrorHandler {
|
||||
static function exception($exception){
|
||||
error_log($exception);
|
||||
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, $exception->getCode());
|
||||
echo '<h1>Oops!</h1><p>Something went wrong!</p>';
|
||||
exit;
|
||||
http_response_code($exception->getCode());
|
||||
$message = [
|
||||
'code' => $exception->getCode(),
|
||||
'message' => $exception->getMessage(),
|
||||
];
|
||||
echo json_encode($message);
|
||||
}
|
||||
}
|
||||
set_exception_handler("ErrorHandler::exception");
|
||||
|
@ -23,10 +23,10 @@ class ApiController {
|
||||
$authManager = new AuthManager();
|
||||
$this->authenticated = $authManager>validateToken($this->headers['HTTP_AUTHORIZATION']);
|
||||
if(!$this->authenticated){
|
||||
throw new Exception("Auth required", 401);
|
||||
throw new Exception("Authorization required", 401);
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Auth required", 401);
|
||||
throw new Exception("Authorization required", 401);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user