Skip to content

Commit

Permalink
Add new (undocumented) PHP-7 JSON error codes, better unknown handling
Browse files Browse the repository at this point in the history
Closes #499
  • Loading branch information
polyfractal committed Nov 15, 2016
1 parent ca2791a commit 0a7fd55
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ class JsonErrorException extends \Exception implements ElasticsearchException
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_RECURSION => 'One or more recursive references in the value to be encoded',
JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded',
JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given',

// 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',

// JSON_ERROR_* constant values that are available on PHP >= 7.0
9 => 'Decoding of value would result in invalid PHP property name', //JSON_ERROR_INVALID_PROPERTY_NAME
10 => 'Attempted to decode nonexistent UTF-16 code-point' //JSON_ERROR_UTF16
);

public function __construct($code, $input, $result, $previous = null)
{
if (isset(self::$messages[$code]) !== true) {
throw new \InvalidArgumentException(sprintf('%d is not a valid JSON error code.', $code));
throw new \InvalidArgumentException(sprintf('Encountered unknown JSON error code: [%d]', $code));
}

parent::__construct(self::$messages[$code], $code, $previous);
Expand Down

0 comments on commit 0a7fd55

Please sign in to comment.