forked from elastic/elasticsearch-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw exception instead of supressing error reporting momentarily.
- Loading branch information
1 parent
5d90aaa
commit aadb82b
Showing
2 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/Elasticsearch/Common/Exceptions/Serializer/JsonErrorException.php
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,60 @@ | ||
<?php | ||
|
||
namespace Elasticsearch\Common\Exceptions\Serializer; | ||
|
||
use Elasticsearch\Common\Exceptions\ElasticsearchException; | ||
|
||
/** | ||
* Class JsonErrorException | ||
* | ||
* @author Bez Hermoso <[email protected]> | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 | ||
* @link http://elasticsearch.org | ||
*/ | ||
class JsonErrorException extends \Exception implements ElasticsearchException | ||
{ | ||
private $input; | ||
|
||
private $result; | ||
|
||
private static $messages = array( | ||
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded', | ||
JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', | ||
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded', | ||
JSON_ERROR_SYNTAX => 'Syntax error', | ||
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', | ||
|
||
// JSON_ERROR_* constant values that are available on PHP >= 5.5.0 | ||
6 => 'One or more recursive references in the value to be encoded', | ||
7 => 'One or more NAN or INF values in the value to be encoded', | ||
8 => 'A value of a type that cannot be encoded was given', | ||
|
||
); | ||
|
||
public function __construct($code, $input, $result, $previous = null) | ||
{ | ||
if (!isset(self::$messages[$code])) { | ||
throw new \InvalidArgumentException('Invalid JSON error code.'); | ||
} | ||
|
||
parent::__construct(self::$messages[$code], $code, $previous); | ||
$this->input = $input; | ||
$this->result = $result; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getInput() | ||
{ | ||
return $this->input; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getResult() | ||
{ | ||
return $this->result; | ||
} | ||
} |
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