mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
better status codes, again
This commit is contained in:
parent
0d70d93e13
commit
c7b637a05f
6 changed files with 78 additions and 7 deletions
12
src/app.php
12
src/app.php
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Demostf\API;
|
||||
|
||||
use Demostf\API\Error\InvalidHashException;
|
||||
use Demostf\API\Error\InvalidKeyException;
|
||||
use Flight;
|
||||
|
||||
/** @var Container $container */
|
||||
|
|
@ -66,4 +68,14 @@ Flight::route('/auth/handle/@token', [$authController, 'handle']);
|
|||
Flight::route('/auth/login/@token', [$authController, 'login']);
|
||||
Flight::route('/auth/logout/@token', [$authController, 'logout']);
|
||||
|
||||
Flight::map('error', function(\Exception $ex){
|
||||
$code = 500;
|
||||
if ($ex instanceof InvalidKeyException) {
|
||||
$code = 401;
|
||||
} else if ($ex instanceof InvalidHashException) {
|
||||
$code = 412;
|
||||
}
|
||||
Flight::response()->status($code)->write($ex->getMessage())->send();
|
||||
});
|
||||
|
||||
Flight::start();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue