Skip to content

Commit 3e3840c

Browse files
committed
"KVClient::get" no longer returns error object on 404 response
1 parent 5d25187 commit 3e3840c

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/KV/KVClient.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,29 @@ public function get($key, QueryOptions $queryOptions = null)
5252
$r = new HttpRequest('get', sprintf('v1/kv/%s', rawurlencode($key)), $this->_Config);
5353
$r->setQueryOptions($queryOptions);
5454

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

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

61-
list($data, $err) = $this->decodeBody($response);
62+
if (200 === $response->httpCode)
63+
{
64+
list($data, $err) = $this->decodeBody($response);
6265

63-
if (null !== $err)
64-
return [null, $qm, $err];
66+
if (null !== $err)
67+
return [null, $qm, $err];
68+
69+
$data = $data[0];
70+
71+
return [Hydrator::KVPair($data), $qm, null];
72+
}
6573

66-
$data = $data[0];
74+
if (404 === $response->httpCode)
75+
return [null, $qm, null];
6776

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

7180
/**

0 commit comments

Comments
 (0)