Skip to content

Wrong JSON error handling  #1012

@HorvathPeterHub

Description

@HorvathPeterHub

Summary of problem or feature request

Above PHP 7.3 the Json error handling in the SmartSerializer has a bug which creates another exception. Instead of the JSON erorr code the error message is passed to the JsonErrorException constructor.

Code snippet of problem

if (version_compare(PHP_VERSION, '7.3.0') >= 0) {
    try {
        $result = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
        return $result;
    } catch (\JsonException $e) {
        $result = $result ?? [];
        throw new JsonErrorException($e->getMessage(), $data, $result);
    }
}

Possible patch would be:

- throw new JsonErrorException($e->getMessage(), $data, $result);
+ throw new JsonErrorException($e->getCode(), $data, $result);

System details

  • Operating System: all
  • PHP Version: above 7.3
  • ES-PHP client version: 7.6.1
  • Elasticsearch version: all

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions