Crell / ApiProblem

A simple implementation of the api-problem specification. Includes PSR-15 support.
MIT License
239 stars 21 forks source link

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

Closed becw closed 8 years ago

becw commented 11 years ago

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

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

Crell commented 11 years ago

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

Crell commented 11 years ago

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

xait-arne-trodahl commented 10 years ago

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

simensen commented 9 years ago

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 commented 8 years ago

JSON has been resolved here: https://github.com/Crell/ApiProblem/pull/14