title: Changing the Content-Type of error responses in the Django Rest Framework?
body: <p>I need <strong>all</strong> error responses in my API to adhere to the <a href="https://datatracker.ietf.org/doc/html/draft-ietf-appsawg-http-problem-00" rel="nofollow noreferrer">Internet Draft &quot;Problem Details for HTTP APIs&quot;</a>, which in the context of the Django Rest Framework could simply mean to change the Content-Type of JSON responses to &quot;application/problem+json&quot;, while successful responses stick with &quot;application/json&quot;. What's the best way to accomplish this?</p>
  <p>I considered creating a custom exception handler that would do the following:</p>
  <ol>
  <li>If &quot;application/problem+json&quot; is not accepted by the client, a &quot;406 Not Acceptable&quot; response is returned.</li>
  <li>Otherwise, call <em>rest_framework.views:exception_handler()</em> and set the response's content type to &quot;application/problem+json&quot;. (Assuming that I have a rendered for this type.)</li>
  </ol>
  <p>Is there a better way to accomplish this? If not, can you spot any problems with this approach?</p>