Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpFoundation] JsonResponse throws an incomprehensible exception if json_encode fails #9903

Closed
@chrisguitarguy

Description

@chrisguitarguy

In JsonResponse::setData json_encode is called then and then JsonEncode::update is called to deal with setting up the content.

If no JS callback is specified and json_encode fails -- returns false -- Response::setContent throws an UnexpectedValueException saying that only strings or objects that have a __toString method are allowed.

I ran into this with an invalid UTF8 character that came out of MySQL.

Seems like this could be improved by checking for a false result on the json_encode call and using json_last_error to generate a nicer error message.

Would that be too detailed for JsonResponse? Should it be up to the caller to make sure they give JsonResponse::setData something valid? Even if it's very hard to tell that something may not work?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions