Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve https://github.com/ruflin/Elastica/issues/1737: handle 413 response #2055

Merged
merged 9 commits into from
Mar 29, 2022
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1959,3 +1959,7 @@ The changelog before version 2.0.0 was organised by date. All changes can be fou

2011-03-21
- ChildrenAggregation added - https://www.elastic.co/guide/en/elasticsearch/guide/current/children-agg.html

2022-03-21
thePanz marked this conversation as resolved.
Show resolved Hide resolved
- Added `\Elastica\Exception\RequestEntityTooLargeException`
- Adjusted `\Elastica\Bulk`, throw RequestEntityTooLargeException if response code 413
thePanz marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions src/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Elastica\Exception\Bulk\ResponseException;
use Elastica\Exception\Bulk\ResponseException as BulkResponseException;
use Elastica\Exception\InvalidException;
use Elastica\Exception\RequestEntityTooLargeException;
use Elastica\Script\AbstractScript;

class Bulk
Expand Down Expand Up @@ -296,6 +297,10 @@ public function send(): ResponseSet
*/
protected function _processResponse(Response $response): ResponseSet
{
switch ($response->getStatus()) {
thePanz marked this conversation as resolved.
Show resolved Hide resolved
case 413: throw new RequestEntityTooLargeException();
thePanz marked this conversation as resolved.
Show resolved Hide resolved
}

$responseData = $response->getData();

$actions = $this->getActions();
Expand Down
11 changes: 11 additions & 0 deletions src/Exception/RequestEntityTooLargeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Elastica\Exception;

class RequestEntityTooLargeException extends \RuntimeException implements ExceptionInterface
{
/**
* @var string
*/
protected $message = 'Request entity is too large.';
thePanz marked this conversation as resolved.
Show resolved Hide resolved
}