1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-04 02:14:06 +02:00

fix type errors

This commit is contained in:
Robin Appelman 2020-11-29 14:46:19 +01:00
commit 3c3b23d1a3
3 changed files with 17 additions and 1 deletions

View file

@ -4,7 +4,10 @@ declare(strict_types=1);
namespace Demostf\API;
use Demostf\API\Error\InvalidHashException;
use Demostf\API\Error\InvalidKeyException;
use Flight;
use flight\net\Response;
/** @var Container $container */
$container = require __DIR__ . '/init.php';
@ -24,4 +27,16 @@ Flight::route('/*', function () {
Flight::route('/upload', [$uploadController, 'upload']);
Flight::route('/do_upload', [$uploadController, 'upload']);
Flight::map('error', function (\Throwable $ex) {
$code = 500;
if ($ex instanceof InvalidKeyException) {
$code = 401;
} elseif ($ex instanceof InvalidHashException) {
$code = 412;
}
/** @var Response $response */
$response = Flight::response()->status($code);
$response->write($ex->getMessage())->send();
});
Flight::start();