# This is example how to rescue from exception ActionDispatch::Http::MimeNegotiation::InvalidType # and show nice JSON error in your API module API class BaseController < ActionController::API def process_action(*args) super rescue ActionDispatch::Http::MimeNegotiation::InvalidType => exception # set valid Content-Type to be able to call render method below request.headers['Content-Type'] = 'application/json' render status: 400, json: { errors: [exception.message] } end end end