Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access logger: read status code from HTTPError, if returned by c.Next() #22

Closed
wants to merge 1 commit into from
Closed

Conversation

kmsb12
Copy link

@kmsb12 kmsb12 commented Jul 14, 2016

The access logger takes the status code, which is being logged, from the LogResponseWriter. If the c.Next() handler does not use WriteHeader, but instead returns a HTTPError, the access logger will log the request with a 200 OK status. (e.g. if serving static files and the requested file does not exist, status code in log will be 200 and not the returned 404)
To fix this, we need to check the error object returned by c.Next() and use its status code if available.

@coveralls
Copy link

coveralls commented Jul 14, 2016

Coverage Status

Coverage remained the same at 95.089% when pulling 1a17ad4 on studio-b12:master into 8c1099a on go-ozzo:master.

@qiangxue
Copy link
Member

You should use fault.Recovery middleware after the access logger. It will correctly handle the error and set response status code.

@kmsb12
Copy link
Author

kmsb12 commented Jul 14, 2016

Thanks for your quick reply. With fault.Recovery it's working fine.

@kmsb12 kmsb12 closed this Jul 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants