I have created a custom REST API plugin for an endpoint. I have set the accepted format to json using the configuration options. This works. However, if we set the content-type to something other than application/json I am getting a 500 error.
I am seeking to know how this exception can be handled more gracefully. However, what is preventing this is the fact that I am not able to get the Request object in the plugin code.
I tried extending the default EventSubscriber services but they do not seem to be of help. I am seeing that this seems to be an open issue in Drupal.org
I am thinking of altering the route and set the default format to json as in manually added custom routes but open to better ways.
Any help would be appreciated.