give the solr 400 error back to php

48 views
Skip to first unread message

Heiko Werner

unread,
Mar 27, 2015, 10:50:44 AM3/27/15
to php-sol...@googlegroups.com
just tried to put the real solr error back to php.
ex. ERROR: [doc=6855245] multiple values encountered for non multiValued field ...

to reach this, overwrite _sendRawPost in Service.php

protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') {
    $httpTransport = $this->getHttpTransport();

    $httpResponse = $httpTransport->performPostRequest($url, $rawPost, $contentType, $timeout);
    $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);

    if ($solrResponse->getHttpStatus() != 200) {
      $tmp = json_decode($solrResponse->getRawResponse(), true);
      if (is_array($tmp['error'])) {
        throw new Apache_Solr_Exception($tmp['error']['msg'], $tmp['error']['status']);
      }
else {
        throw new Apache_Solr_HttpTransportException($solrResponse);
      }
    }
    return $solrResponse;
  }



hope this helps...
[it's better to adapt Apache_Solr_HttpTransportException but this needs to change the svn code!]

regards heiko

Donovan Jimenez

unread,
Mar 27, 2015, 11:04:15 AM3/27/15
to php-sol...@googlegroups.com
you can do exactly what you're doing in the code that tries to add the docs - without modifying the client.... 

the Apache_Solr_HttpTransportException is fed the full Apache_Solr_Response - so that you can retrieve it from the exception and do as you like.

https://github.com/PTCInc/solr-php-client/blob/master/Apache/Solr/HttpTransportException.php#L62

for example:

try {
  // do some solr action, search, add, whatever
  $solr->...(...);
} catch (Apache_Solr_HttpTransportException $hte) {
  // get the response
  $response = $hte->getResponse();
  
  // this has status and message on it already
  $response->getHttpStatus();
  $response->getHttpStatusMessage();

  // or you can get the raw response, like you did above if that's what you want 
  $rawResponse = $response->getRawResponse();
  $error = json_decode($rawResponse, true);
}


--
You received this message because you are subscribed to the Google Groups "PHP Solr Client" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-solr-clie...@googlegroups.com.
To post to this group, send email to php-sol...@googlegroups.com.
Visit this group at http://groups.google.com/group/php-solr-client.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages