Apipie / apipie-rails

Ruby on Rails API documentation tool
Apache License 2.0
2.47k stars 463 forks source link

Wrong HTTP error returns #274

Open liorsion opened 10 years ago

liorsion commented 10 years ago

Hi,

When an error returns and an ApiPie exception is raised, since it's a custom error and no one catches it, HTTP error 500 returns, which is wrong (http error 500 is internal server error - it should be 400, like rails bad request

A simple solution would be to add something like this to the Errors class:

module RescueError

def self.included(base)
  base.rescue_from Apipie::Error do |e|
    # render "public/404", :status => 404
    respond_to do |format|
      format.html { render :show, status: @status_code, layout: !request.xhr? }
      format.xml  { render xml: e, root: "error", status: 400 }
      format.json { render json: {error: e}, status: 400 }
    end
  end
end

end

then change the docs to ask people to add include Apipie::RescueError to the base controller or the Api base controller, whatever they use.

What do you think? If approved I'll send a pull request

iNecas commented 10 years ago

Sounds reasonable to me

ilyakatz commented 6 years ago

did this PR ever happen?

damuz91 commented 4 years ago

Great, this saved my life; thanks!; i wonder why by design the apipie returns an error 500 on production mode instead of a nice description like in dev?