Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle JSON errors when decoding #68

Merged
merged 3 commits into from
Mar 31, 2020
Merged

Handle JSON errors when decoding #68

merged 3 commits into from
Mar 31, 2020

Conversation

aschempp
Copy link
Member

not sure if we should handle that exception …

Comment on lines 205 to 207
if (!\is_array($content)) {
throw new \RuntimeException('Invalid JSON: '.json_last_error_msg());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!\is_array($content)) {
throw new \RuntimeException('Invalid JSON: '.json_last_error_msg());
}
if (JSON_ERROR_NONE !== json_last_error()) {
throw new \JsonException(json_last_error_msg());
}
if (!\is_array($content)) {
throw new \InvalidArgumentException('Invalid JSON data: expected array, got "%s"', gettype($content)));
}

How about this?

Copy link
Member Author

@aschempp aschempp Mar 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JsonException is only available from PHP 7.4 😉
and with 7.4 we could just tell JSON to throw that exception

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we could, but why would we need different exceptions at all? 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using the polyfill already since #63

@ausi ausi self-assigned this Mar 12, 2020
@ausi ausi added the bug label Mar 12, 2020
Copy link
Member

@ausi ausi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR to work similar to the fix from #63.

Are you OK with these changes?

@aschempp
Copy link
Member Author

👍

@ausi ausi changed the title Fix invalid method return value Handle JSON errors when decoding Mar 31, 2020
@ausi ausi merged commit 4142d7c into contao:master Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants