gorilla/mux — pull request #26 by johnnadratowski (2013-06-06 20:57:41+00:00)
Title: Better error messages

I opened bug #21, which was duplicate of #6 with more information. This pull request implements *most* of the suggestions from there. I didn't get fancy with the header missing requests, so I just ended up using 412 regardless of the headers (some headers, per the protocol, should use different codes, it seems).

I have a good amount of tests in there, and a couple of helper methods. I have implemented a new NotFound method handler (the default was the one from net/http, which is still used if my code doesn't find an error match).

I saw the response from @nesv about how it would take a lot of refactoring. I kind of skirted around that by using the context to store error messages/codes that the default NotFound() handler looks for. If those context variables aren't found, it defaults to the http.NotFound handler. I thought this would be ok since this package is already tied to gorilla/context since it has the clearing of the context in ServeHTTP.

I hope this is accepted by the project. I think this is a good way of handling custom errors, and it seems to fit in with being able to write your own matchers, as custom matchers aren't excluded from being able to set context.

If you notice that there is some code that shows up in the diff around clearing the context, it's because I have another pull request for optionally turning off context clearing. However, I forgot to make a topic branch before I did the implementation for that *facepalm*. I took that logic out of the code before I started this topic branch, and I double checked that the code from that pull request was taken out, but it still shows up in the diff.

Please let me know if there are any changes you want from me for this pull request.

Thanks!