title: rails 5 api app with json error response instead of html error response
body: <p>If I create an app in rails using the --api flag my error responses are in html rather than json.</p>
  
  <p>How am I able to change the default error handler so that whenever an error is thrown in a controller action, I receive a json only response with the error and http status?</p>
  
  <p>right now I am using the code below in every custom action</p>
  
  <pre><code>rescue =&gt; e
      response.status = 422
      render json: { error: e.message }
  </code></pre>
  
  <p>I'd rather not have to add this each time...</p>
  
  <p>UPDATE: 
  I used the rescue_from method in the application controller</p>
  
  <pre><code>rescue_from Exception do |exception|
      render json: exception, status: 500
  end
  </code></pre>
  
  <p>But I feel this is very wrong and the status will always be hard coded as 500</p>