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

fromJson method doesn't throw an appropriate exception for invalid JSON #3

Closed
becw opened this issue May 15, 2013 · 5 comments
Closed

Comments

@becw
Copy link

becw commented May 15, 2013

When invalid JSON is passed to ApiProblem::fromJson(), I get a PHP notice and an exception:

  • Argument 1 passed to Crell\ApiProblem\ApiProblem::decompile() must be an array, null given
  • The provided problem string is invalid. The "title" property is required.

I think it would be appropriate to throw an exception about the invalid JSON, rather than one about the missing title.

@Crell
Copy link
Owner

Crell commented Jun 28, 2013

Hm, I would agree. How do we detect invalid JSON, though? Please file a PR. :-)

@Crell
Copy link
Owner

Crell commented Jun 28, 2013

We should probably do the same for unparsable XML, too.

@xait-arne-trodahl
Copy link

Some clues can be found in the examples here http://php.net/manual/en/function.json-last-error.php

@simensen
Copy link
Contributor

simensen commented Dec 9, 2014

For JSON you can consider using seld/jsonlint as that can check to make sure that the JSON is well-formed. It does not help the XML problem.

https://packagist.org/packages/seld/jsonlint

@Crell
Copy link
Owner

Crell commented May 2, 2016

JSON has been resolved here: #14

@Crell Crell closed this as completed May 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants