Skip to content

Commit e882a64

Browse files
committed
Updated Type::getDocument() exception handling ruflin#687
1 parent 4444547 commit e882a64

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

changes.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CHANGES
22

3+
2014-10-29
4+
- Updated Type::getDocument() exception handling #687
5+
36
2014-10-22
47
- Added Util::convertDateTimeObject to Util class to easily convert \DateTime objects to required format #708
58

lib/Elastica/Type.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,10 @@ public function getDocument($id, $options = array())
226226
{
227227
$path = urlencode($id);
228228

229-
try {
230-
$response = $this->request($path, Request::GET, array(), $options);
231-
$result = $response->getData();
232-
} catch (ResponseException $e) {
233-
throw new NotFoundException('unable to retrieve doc id ' . $id. ': '.$e->getMessage(), $e->getCode(), $e);
234-
}
229+
$response = $this->request($path, Request::GET, array(), $options);
230+
$result = $response->getData();
235231

236-
$info = $response->getTransferInfo();
237-
if ($info['http_code'] !== 200) {
232+
if (!isset($result['found']) || $result['found'] === false) {
238233
throw new NotFoundException('doc id ' . $id . ' not found');
239234
}
240235

test/lib/Elastica/Test/TypeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public function testGetDocumentNotExist()
329329
}
330330

331331
/**
332-
* @expectedException \Elastica\Exception\NotFoundException
332+
* @expectedException \Elastica\Exception\ResponseException
333333
*/
334334
public function testGetDocumentNotExistingIndex()
335335
{

0 commit comments

Comments
 (0)