Logging wrong HTTP status code for not_found #7646

Closed
jacobat opened this Issue Sep 14, 2012 · 3 comments

Projects

None yet

4 participants

@jacobat
Contributor
jacobat commented Sep 14, 2012

When an ActiveRecord::RecordNotFound is raised in a Rails application a status code of 404 is returned to the client:

curl -I http://localhost:3000/users
HTTP/1.1 404 Not Found 
...

But a status code of 500 is logged:

Started HEAD "/users" for 127.0.0.1 at 2012-09-14 22:11:54 +0200
Processing by UsersController#index as */*
Completed 500 Internal Server Error in 0ms

ActiveRecord::RecordNotFound (ActiveRecord::RecordNotFound):
  app/controllers/users_controller.rb:3:in `index'

I would expect it to log the same HTTP status code in the log file as is returned to the user.

I've amended the Railties test so it shows the issue in this commit: jacobat@c9e4a4f

@steveklabnik
Member

Okay. So. https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/log_subscriber.rb#L24 uses Rack::Utils::HTTP_STATUS_CODES, which defaults to 500 if it can't find the key. The status is 500 there already, though, so the error happens farther up. Hmmm.

@senny
Member
senny commented Sep 16, 2012

I found the issue and submitted a PR.

@rafaelfranca
Member

Fixed by 8f0d332

@rafaelfranca rafaelfranca added a commit that referenced this issue Sep 17, 2012
@senny @rafaelfranca senny + rafaelfranca log 404 status when ActiveRecord::RecordNotFound was raised (#7646)
Conflicts:
	actionpack/CHANGELOG.md
	actionpack/lib/action_controller/log_subscriber.rb
dd76b3b
@sikachu sikachu added a commit that referenced this issue Sep 17, 2012
@senny @sikachu senny + sikachu log 404 status when ActiveRecord::RecordNotFound was raised (#7646)
Conflicts:
	actionpack/CHANGELOG.md
	actionpack/lib/action_controller/log_subscriber.rb
33cb95d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment