mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 09:54:17 +02:00
fix type errors
This commit is contained in:
parent
3f9e613e77
commit
3c3b23d1a3
3 changed files with 17 additions and 1 deletions
|
|
@ -68,6 +68,7 @@ class Demo implements JsonSerializable {
|
|||
$this->backend = $backend;
|
||||
$this->path = $path;
|
||||
$this->players = [];
|
||||
$this->uploaderUser = null;
|
||||
}
|
||||
|
||||
public function getId(): int {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ 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) {
|
||||
Flight::map('error', function (\Throwable $ex) {
|
||||
$code = 500;
|
||||
if ($ex instanceof InvalidKeyException) {
|
||||
$code = 401;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue