diff --git a/app/Enums/ApiError.php b/app/Enums/ApiError.php index 61b667b..7e1c9a2 100644 --- a/app/Enums/ApiError.php +++ b/app/Enums/ApiError.php @@ -47,6 +47,9 @@ use Kwaadpepper\Enum\BaseEnumRoutable; * a replay attack scenario. Timestamps are provided in headers * and in the http body * + * @method static self missingParameter() + * The request is missing some parameters + * * @method static self throttleRequestsException() * Too many requests have been attempted. The is a throttle security. * Normally you should not trigger this. @@ -78,6 +81,7 @@ class ApiError extends BaseEnumRoutable 'singleOptinCustomerExists' => 120, 'methodNotAllowed' => 150, 'wrongTimeStamp' => 151, + 'missingParameter' => 400, 'authorizationException' => 403, 'throttleRequestsException' => 429 ]; @@ -96,6 +100,7 @@ class ApiError extends BaseEnumRoutable 'needAuth' => 'Vous devez être authentifié', 'methodNotAllowed' => 'This method is not allowed for this request', 'wrongTimeStamp' => 'Your request is malformed, please check timestamp header and parameter', + 'missingParameter' => 'The request is missing some parameters', 'authorizationException' => 'You are not autorized to access this', 'throttleRequestsException' => 'Throttle: too many request have been attempted, please retry later' ]; diff --git a/app/Http/Controllers/Api/V2/ApiController.php b/app/Http/Controllers/Api/V2/ApiController.php index 6be7a29..61455f5 100644 --- a/app/Http/Controllers/Api/V2/ApiController.php +++ b/app/Http/Controllers/Api/V2/ApiController.php @@ -20,6 +20,9 @@ class ApiController extends Controller public function authenticate(Request $request) { try { + if (!$request->bearerToken()) { + throw new ApiErrorException(ApiError::missingParameter()); + } /** @var \App\Models\Service */ $service = Service::getFromBearerToken($request->bearerToken()); } catch (ModelNotFoundException $e) {