Skip to content

Commit

Permalink
"KVClient::get" no longer returns error object on 404 response
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Jul 21, 2016
1 parent 5d25187 commit 3e3840c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/KV/KVClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,29 @@ public function get($key, QueryOptions $queryOptions = null)
$r = new HttpRequest('get', sprintf('v1/kv/%s', rawurlencode($key)), $this->_Config);
$r->setQueryOptions($queryOptions);

list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
/** @var \DCarbone\PHPConsulAPI\HttpResponse $response */
list($duration, $response, $err) = $this->doRequest($r);
$qm = $this->buildQueryMeta($duration, $response);

if (null !== $err)
return [null, $qm, $err];

list($data, $err) = $this->decodeBody($response);
if (200 === $response->httpCode)
{
list($data, $err) = $this->decodeBody($response);

if (null !== $err)
return [null, $qm, $err];
if (null !== $err)
return [null, $qm, $err];

$data = $data[0];

return [Hydrator::KVPair($data), $qm, null];
}

$data = $data[0];
if (404 === $response->httpCode)
return [null, $qm, null];

return [Hydrator::KVPair($data), $qm, null];
return [null, $qm, new Error(sprintf('%s: %s', $response->httpCode, $response->body))];
}

/**
Expand Down

0 comments on commit 3e3840c

Please sign in to comment.