-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw an exception when one or more bulk operations were unsuccessful
- Loading branch information
1 parent
d3b5daa
commit e4a2a64
Showing
4 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace ElasticAdapter\Exceptions; | ||
|
||
use ErrorException; | ||
|
||
final class BulkRequestException extends ErrorException | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $response; | ||
|
||
public function __construct(array $response) | ||
{ | ||
parent::__construct('One or more operations in the bulk request did not complete successfully'); | ||
$this->response = $response; | ||
} | ||
|
||
public function getResponse(): array | ||
{ | ||
return $this->response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace ElasticAdapter\Tests\Unit\Exceptions; | ||
|
||
use ElasticAdapter\Exceptions\BulkRequestException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \ElasticAdapter\Exceptions\BulkRequestException | ||
*/ | ||
final class BulkRequestExceptionTest extends TestCase | ||
{ | ||
public function test_response_can_be_retrieved(): void | ||
{ | ||
$response = [ | ||
'took' => 486, | ||
'errors' => true, | ||
'items' => [ | ||
[ | ||
'update' => [ | ||
'_index' => 'index1', | ||
'_type' => '_doc', | ||
'_id' => '5', | ||
'status' => 404, | ||
'error' => [ | ||
'type' => 'document_missing_exception', | ||
'reason' => '[_doc][5]: document missing', | ||
'index_uuid' => 'aAsFqTI0Tc2W0LCWgPNrOA', | ||
'shard' => '0', | ||
'index' => 'index1', | ||
], | ||
], | ||
], | ||
], | ||
]; | ||
|
||
$exception = new BulkRequestException($response); | ||
|
||
$this->assertSame($response, $exception->getResponse()); | ||
} | ||
} |