http_status_exceptions icon indicating copy to clipboard operation
http_status_exceptions copied to clipboard

Rails log shows Internal Server Error when handling HTTPStatus exceptions

Open haxney opened this issue 14 years ago • 7 comments

I am throwing an HTTPStatus::BadRequest exception in my controller when a request is invalid. The server correctly replies with a 400 status code and whatever template I give it, but the log in the server console shows:

Started GET "/bla?arg=invalid" for 127.0.0.1 at 2011-08-11 20:14:21 -0400
  Processing by BlasController#index as HTML
  Parameters: {"arg"=>"invalid"}
Completed 500 Internal Server Error in 1ms
Rendered exceptions/bad_request.html.erb within layouts/application (4.0ms)

So everything is returned correctly, but an incorrect value shows up in the log. It isn't the biggest problem, since as far as the client is concerned, everything is normal. But the log messages aren't very useful, since there's no differentiation between the different kinds of exceptions raised.

Thanks for an awesome yet simple gem!

haxney avatar Aug 12 '11 00:08 haxney

This sounds like a bug I fixed in Rails (https://github.com/rails/rails/pull/2133). Are you raising that exception inside of a rescue_from block?

jstorimer avatar Aug 12 '11 02:08 jstorimer

I'm using Rails 3.0.9; was your fix included in that? I'm raising the exceptions from the controller, not anything fancy :)

haxney avatar Aug 12 '11 05:08 haxney

This patch seems to be in the master branch, so it hasn't been released yet and will be part of Rails 3.1. Can you try if the problem persists in Rails master to make sure this is the actual problem?

wvanbergen avatar Aug 12 '11 12:08 wvanbergen

Got it. I'll try this out when I get a chance.

haxney avatar Aug 12 '11 16:08 haxney

It should also be in the next release of the 3.0.x branch, so 3.0.10.

jstorimer avatar Aug 13 '11 01:08 jstorimer

Any update on this issue?

Fluxx avatar Sep 24 '11 04:09 Fluxx

@jstorimer's patch was included in the Rails 3.0.10 release. Can you check if it works for you after upgrading? It should be working for 3.1 as well.

wvanbergen avatar Sep 24 '11 15:09 wvanbergen