Skip to content

Commit 0a7fd55

Browse files
committed
Add new (undocumented) PHP-7 JSON error codes, better unknown handling
Closes #499
1 parent ca2791a commit 0a7fd55

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Elasticsearch/Common/Exceptions/Serializer/JsonErrorException.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@ class JsonErrorException extends \Exception implements ElasticsearchException
3131
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
3232
JSON_ERROR_SYNTAX => 'Syntax error',
3333
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded',
34+
JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded',
35+
JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded',
36+
JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given',
3437

35-
// JSON_ERROR_* constant values that are available on PHP >= 5.5.0
36-
6 => 'One or more recursive references in the value to be encoded',
37-
7 => 'One or more NAN or INF values in the value to be encoded',
38-
8 => 'A value of a type that cannot be encoded was given',
39-
38+
// JSON_ERROR_* constant values that are available on PHP >= 7.0
39+
9 => 'Decoding of value would result in invalid PHP property name', //JSON_ERROR_INVALID_PROPERTY_NAME
40+
10 => 'Attempted to decode nonexistent UTF-16 code-point' //JSON_ERROR_UTF16
4041
);
4142

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

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

0 commit comments

Comments
 (0)