captchaEnabled) { return $handler->handle($request); } $params = $request->getParsedBody(); $param = 'captcha-token'; $token = $params->$param ?? null; if (!$token) { throw new ValidationException( 'Missing captcha token in request body', $param ); } if (!is_string($token)) { throw new ValidationException( 'Captcha token must be a string', $param ); } try { $this->captcha->verifyToken($token); } catch (VerificationFailedException $th) { throw new ValidationException( 'Captcha verification failed', $param ); } return $handler->handle($request); } }