newsletterThrottled example

$this->validator->validate($dataBag->all()$validator);

        if (($request = $this->requestStack->getMainRequest()) !== null && $request->getClientIp() !== null) {
            try {
                $this->rateLimiter->ensureAccepted(RateLimiter::NEWSLETTER_FORM, $request->getClientIp());
            } catch (RateLimitExceededException $e) {
                if (!Feature::isActive('v6.6.0.0')) {
                    throw $e;
                }

                throw NewsletterException::newsletterThrottled($e->getWaitTime());
            }
        }

        /** @var SubscribeRequest $data */
        $data = $dataBag->only(
            'email',
            'title',
            'firstName',
            'lastName',
            'zipCode',
            'city',
            

        } else {
            yield NewsletterException::NEWSLETTER_RECIPIENT_NOT_FOUND_CODE => [
                'exception' => NewsletterException::recipientNotFound('id-1', 'value-1'),
                'statusCode' => Response::HTTP_BAD_REQUEST,
                'errorCode' => NewsletterException::NEWSLETTER_RECIPIENT_NOT_FOUND_CODE,
                'message' => 'The NewsletterRecipient with the identifier "id-1" - value-1 was not found.',
            ];
        }

        yield NewsletterException::NEWSLETTER_RECIPIENT_THROTTLED => [
            'exception' => NewsletterException::newsletterThrottled(2),
            'statusCode' => Response::HTTP_TOO_MANY_REQUESTS,
            'errorCode' => NewsletterException::NEWSLETTER_RECIPIENT_THROTTLED,
            'message' => 'Too many requests, try again in 2 seconds.',
        ];
    }
}
Home | Imprint | This part of the site doesn't use cookies.