1
0
Fork 0
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:
Robin Appelman 2020-11-25 23:26:54 +01:00
commit c7b637a05f
6 changed files with 78 additions and 7 deletions

View file

@ -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();