Skip to content

Commit

Permalink
Updated Type::getDocument() exception handling ruflin#687
Browse files Browse the repository at this point in the history
  • Loading branch information
rmruano committed Oct 29, 2014
1 parent 4444547 commit e882a64
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
3 changes: 3 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CHANGES

2014-10-29
- Updated Type::getDocument() exception handling #687

2014-10-22
- Added Util::convertDateTimeObject to Util class to easily convert \DateTime objects to required format #708

Expand Down
11 changes: 3 additions & 8 deletions lib/Elastica/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,10 @@ public function getDocument($id, $options = array())
{
$path = urlencode($id);

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/lib/Elastica/Test/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public function testGetDocumentNotExist()
}

/**
* @expectedException \Elastica\Exception\NotFoundException
* @expectedException \Elastica\Exception\ResponseException
*/
public function testGetDocumentNotExistingIndex()
{
Expand Down

0 comments on commit e882a64

Please sign in to comment.