nilportugues / php-json-api

JSON API transformer outputting valid (PSR-7) API Responses.
http://nilportugues.com
MIT License
71 stars 35 forks source link

Silent DataException in DataObject #88

Open derrekbertrand opened 7 years ago

derrekbertrand commented 7 years ago

https://github.com/nilportugues/php-json-api/blob/master/src/Server/Data/DataObject.php#L51

While testing some stuff out in the Laravel wrapper, I realized that you can trigger an exception here by setting the type to text instead of a JSON request. The data won't be filled out right, and the assert fails. Unfortunately, this line just eats the assertion, and happily lets it crash later.

derrekbertrand commented 7 years ago

Look's like it is the Laravel wrapper's fault... partially. In non-debug mode, it dumps this message, but that doesn't really explain the error, just that your request setup is wrong.

Honestly, I think just commenting what that try-catch block does might help a lot.

{
  "errors": [
    {
      "status": 400,
      "title": "Bad Request",
      "detail": "Request could not be served."
    }
  ]
}