You are here

final protected function SolrConnectorPluginBase::handleHttpException in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::handleHttpException()
  2. 8 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::handleHttpException()
  3. 8.2 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::handleHttpException()

Converts a HttpException in an easier to read SearchApiSolrException.

Connectors must not overwrite this function. Otherwise support requests are hard to handle in the issue queue. If you want to extend this function and add more sophisticated error handling, please contribute a patch to the search_api_solr project on drupal.org.

Parameters

\Solarium\Exception\HttpException $e: The HttpException object.

\Solarium\Core\Client\Endpoint $endpoint: The Solarium endpoint.

Throws

\Drupal\search_api_solr\SearchApiSolrException

2 calls to SolrConnectorPluginBase::handleHttpException()
SolrConnectorPluginBase::execute in src/SolrConnector/SolrConnectorPluginBase.php
Executes any query.
SolrConnectorPluginBase::executeRequest in src/SolrConnector/SolrConnectorPluginBase.php
Executes a request and returns the response.

File

src/SolrConnector/SolrConnectorPluginBase.php, line 997

Class

SolrConnectorPluginBase
Defines a base class for Solr connector plugins.

Namespace

Drupal\search_api_solr\SolrConnector

Code

protected final function handleHttpException(HttpException $e, Endpoint $endpoint) {
  $body = $e
    ->getBody();
  $response_code = (int) $e
    ->getCode();
  switch ((string) $response_code) {
    case '400':

      // Bad Request.
      $description = 'bad request';
      $response_decoded = Json::decode($body);
      if ($response_decoded && isset($response_decoded['error'])) {
        $body = $response_decoded['error']['msg'] ?? $body;
      }
      break;
    case '404':

      // Not Found.
      $description = 'not found';
      break;
    case '401':

    // Unauthorized.
    case '403':

      // Forbidden.
      $description = 'access denied';
      break;
    case '500':

    // Internal Server Error.
    case '0':
      $description = 'internal Solr server error';
      break;
    default:
      $description = 'unreachable or returned unexpected response code';
  }
  throw new SearchApiSolrException(sprintf('Solr endpoint %s %s (code: %d, body: %s, message: %s).', $this
    ->getEndpointUri($endpoint), $description, $response_code, $body, $e
    ->getMessage()), $response_code, $e);
}