mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 09:54:17 +02:00
dont try to set invalid status codes
This commit is contained in:
parent
5b3a66a8c1
commit
b06cf67a70
2 changed files with 12 additions and 5 deletions
|
|
@ -74,8 +74,12 @@ Flight::map('error', function (\Throwable $ex) {
|
||||||
if ($ex->getCode()) {
|
if ($ex->getCode()) {
|
||||||
$code = $ex->getCode();
|
$code = $ex->getCode();
|
||||||
}
|
}
|
||||||
/** @var Response $response */
|
$response = Flight::response();
|
||||||
$response = Flight::response()->status($code);
|
if (array_key_exists($code, Response::$codes)) {
|
||||||
|
$response->status($code);
|
||||||
|
} else {
|
||||||
|
$response->status(500);
|
||||||
|
}
|
||||||
$response->write($ex->getMessage())->send();
|
$response->write($ex->getMessage())->send();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Demostf\API;
|
namespace Demostf\API;
|
||||||
|
|
||||||
use Demostf\API\Error\InvalidHashException;
|
|
||||||
use Demostf\API\Error\InvalidKeyException;
|
|
||||||
use Flight;
|
use Flight;
|
||||||
use flight\net\Response;
|
use flight\net\Response;
|
||||||
|
|
||||||
|
|
@ -33,7 +31,12 @@ Flight::map('error', function (\Throwable $ex) {
|
||||||
$code = $ex->getCode();
|
$code = $ex->getCode();
|
||||||
}
|
}
|
||||||
/** @var Response $response */
|
/** @var Response $response */
|
||||||
$response = Flight::response()->status($code);
|
$response = Flight::response();
|
||||||
|
if (array_key_exists($code, Response::$codes)) {
|
||||||
|
$response->status($code);
|
||||||
|
} else {
|
||||||
|
$response->status(500);
|
||||||
|
}
|
||||||
$response->write($ex->getMessage())->send();
|
$response->write($ex->getMessage())->send();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue