Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294415

Incorrect use of UnprocessableHttpEntityException in EntityResource::deserialize()

$
0
0

The EntityResource controller class has a deserialize() method which takes care of building the entity object from the submitted request data.

At some point, if either UnexpectedValueException or InvalidArgumentException are thrown by the underlying serialized, it is catched and an UnprocessableHttpEntityException is thrown by the method itself.

    try {
      ...
    }
    // These two serialization exception types mean there was a problem with
    // the structure of the decoded data and it's not valid.
    catch (UnexpectedValueException $e) {
      throw new UnprocessableHttpEntityException($e->getMessage());
    }
    catch (InvalidArgumentException $e) {
      throw new UnprocessableHttpEntityException($e->getMessage());
    }

The issue here is that, per its signature, UnprocessableHttpEntityException first argument should be an Exception object, not a string. When one of this situation occurs, a TypeError is thrown by PHP, breaking the execution flow and leading to a 5xx error instead of a JSON:API managed 4xx error.


Viewing all articles
Browse latest Browse all 294415

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>