Skip to content
Snippets Groups Projects
Commit 047d7844 authored by David Maus's avatar David Maus
Browse files

Implement and use factory for BackendException

* VuFindSearch/Backend/Solr/Connector.php (send): Use exception
  factory.
* VuFindSearch/Backend/Exception/BackendException.php
  (createFromResponse): New function. Create exception based on
  server response.
parent 399d6062
No related merge requests found
......@@ -60,6 +60,27 @@ class BackendException extends RuntimeException
*/
protected $response;
/**
* Exception factory.
*
* Returns a RequestErrorException or RemoteErrorException depending on
* the response's status code.
*
* @param Response $response Server response
*
* @return RequestErrorException|RemoteErrorException
*/
public static function createFromResponse(Response $response)
{
$status = $response->getStatusCode();
$phrase = $response->getReasonPhrase();
if ($status >= 500) {
return new RemoteErrorException($phrase, $status, $response);
} else {
return new RequestErrorException($phrase, $status, $response);
}
}
/**
* Constructor.
*
......
......@@ -37,9 +37,7 @@ use VuFindSearch\Query\Query;
use VuFindSearch\ParamBag;
use VuFindSearch\Backend\Exception\RemoteErrorException;
use VuFindSearch\Backend\Exception\RequestErrorException;
use VuFindSearch\Backend\Exception\RequestParseErrorException;
use VuFindSearch\Backend\Exception\BackendException;
use VuFindSearch\Backend\Solr\Document\AbstractDocument;
......@@ -405,13 +403,7 @@ class Connector
}
if (!$response->isSuccess()) {
$status = $response->getStatusCode();
$phrase = $response->getReasonPhrase();
if ($status >= 500) {
throw new RemoteErrorException($phrase, $status, $response);
} else {
throw new RequestErrorException($phrase, $status, $response);
}
throw BackendException::createFromResponse($response);
}
return $response->getBody();
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment