go-ozzo / ozzo-routing

An extremely fast Go (golang) HTTP router that supports regular expression route matching. Comes with full support for building RESTful APIs.
MIT License
453 stars 51 forks source link

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

Closed kmsb12 closed 8 years ago

kmsb12 commented 8 years ago

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 commented 8 years ago

Coverage Status

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

qiangxue commented 8 years ago

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

kmsb12 commented 8 years ago

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