/**
  * Detect parser error response.
  *
  * @return void
  */
 public function testDetectUndefinedFieldError()
 {
     $response = $this->createResponse('solr4-undefined-field-error');
     $backend = $this->getMockForAbstractClass('VuFindSearch\\Backend\\BackendInterface');
     $exception = HttpErrorException::createFromResponse($response);
     $params = ['backend_instance' => $backend];
     $event = new Event(null, $exception, $params);
     $listener = new ErrorListener($backend);
     $listener->onSearchError($event);
     $this->assertTrue($exception->hasTag('VuFind\\Search\\ParserError'));
 }
Exemple #2
0
 /**
  * Check for HTTP errors in a response.
  *
  * @param \Zend\Http\Response $result The response to check.
  *
  * @throws BackendException
  * @return void
  */
 public function checkForHttpError($result)
 {
     if (!$result->isSuccess()) {
         throw HttpErrorException::createFromResponse($result);
     }
 }
Exemple #3
0
 /**
  * Send a request and return the response.
  *
  * @param \Zend\Http\Client $client Prepare HTTP client
  *
  * @return string Response body
  *
  * @throws \VuFindSearch\Backend\Exception\RemoteErrorException  Server
  * signaled a server error (HTTP 5xx)
  * @throws \VuFindSearch\Backend\Exception\RequestErrorException Server
  * signaled a client error (HTTP 4xx)
  */
 protected function send(\Zend\Http\Client $client)
 {
     $this->debug(sprintf('=> %s %s', $client->getMethod(), $client->getUri()));
     $time = microtime(true);
     $response = $client->send();
     $time = microtime(true) - $time;
     $this->debug(sprintf('<= %s %s', $response->getStatusCode(), $response->getReasonPhrase()), ['time' => $time]);
     if (!$response->isSuccess()) {
         throw HttpErrorException::createFromResponse($response);
     }
     return $response->getBody();
 }