Skip to content

Commit

Permalink
Backward compatibility (#651)
Browse files Browse the repository at this point in the history
* Backward compatibility: getBaseUri() now throws an UnexpectedValueException and we don't send a request. In previous version we sent the request which resulted in HttpException.
  • Loading branch information
Markus Kalkbrenner authored Feb 6, 2019
1 parent bc0b705 commit 7c3b8ee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
30 changes: 23 additions & 7 deletions src/Core/Client/Adapter/AdapterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,38 @@

use Solarium\Core\Client\Endpoint;
use Solarium\Core\Client\Request;
use Solarium\Exception\HttpException;
use Solarium\Exception\UnexpectedValueException;

/**
* Helper class for shared adapter functionality.
*/
class AdapterHelper
{
/**
* @param Request $request
* @param Endpoint $endpoint
*
* @return string
*
* @throws HttpException
*/
public static function buildUri(Request $request, Endpoint $endpoint): string
{
if (Request::API_V2 == $request->getApi()) {
$baseUri = $endpoint->getV2BaseUri();
} elseif ($request->getIsServerRequest()) {
$baseUri = $endpoint->getV1BaseUri();
} else {
$baseUri = $endpoint->getBaseUri();
try {
if (Request::API_V2 == $request->getApi()) {
$baseUri = $endpoint->getV2BaseUri();
} elseif ($request->getIsServerRequest()) {
$baseUri = $endpoint->getV1BaseUri();
} else {
$baseUri = $endpoint->getBaseUri();
}
return $baseUri.$request->getUri();
} catch (UnexpectedValueException $e) {
// Backward compatibility: getBaseUri() now throws an UnexpectedValueException and we don't send a request.
// In previous version we sent the request which resulted in HttpException.
throw new HttpException($e->getMessage(), 404, $e->getTraceAsString());
}
return $baseUri.$request->getUri();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/HttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HttpException extends \RuntimeException implements ExceptionInterface
* Exception constructor.
*
* The input message is a HTTP status message. Because an exception with the
* message 'Not Found' is not very clear it this message is tranformed to a
* message 'Not Found' is not very clear this message is transformed to a
* more descriptive text. The original message is available using the
* {@link getStatusMessage} method.
*
Expand Down

0 comments on commit 7c3b8ee

Please sign in to comment.