Skip to content
Snippets Groups Projects

Issue #3313839: Added link to flood control error message

Closed Issue #3313839: Added link to flood control error message
All threads resolved!
Closed Balint Pekker requested to merge issue/acquia_search-3313839:3313839-add-link-to into 3.1.x
All threads resolved!
Files
2
@@ -7,6 +7,7 @@ use Drupal\acquia_search\AcquiaCryptConnector;
use Drupal\acquia_search\Helper\Flood;
use Drupal\acquia_search\PreferredCoreService;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Solarium\Core\Client\Adapter\AdapterHelper;
use Solarium\Core\Client\Response;
use Solarium\Core\Event\Events;
@@ -23,6 +24,8 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
*/
class SearchSubscriber extends AbstractPlugin implements EventSubscriberInterface {
use StringTranslationTrait;
/**
* Acquia search endpoint.
*
@@ -110,11 +113,13 @@ class SearchSubscriber extends AbstractPlugin implements EventSubscriberInterfac
// Run Flood control checks.
if (!Flood::isAllowed($request->getHandler())) {
// If request should be blocked, show an error message.
$message = 'The Acquia Search flood control mechanism has blocked a Solr query due to API usage limits. You should retry in a few seconds. Contact the site administrator if this message persists.';
$message = $this->t('<a href=":link">The Acquia Search flood control mechanism has blocked a Solr query due to API usage limits.</a> You should retry in a few seconds. Contact the site administrator if this message persists.', [
':link' => Flood::FLOOD_LIMIT_ARTICLE_URL,
]);
\Drupal::messenger()->addError($message);
// Build a static response which avoids a network request to Solr.
$response = new Response($message, ['HTTP/1.1 429 Too Many Requests']);
$response = new Response((string) $message, ['HTTP/1.1 429 Too Many Requests']);
$event->setResponse($response);
$event->stopPropagation();
return;
Loading