Commit 9dfbbbcd authored by Matthew Holt's avatar Matthew Holt

errors: Pointer to handler prevents nil pointer errors in handling (fixes #15)

If we do not use a pointer here, the startup function that opens the log file stores the log file in a copy of the handler, not the same instance of the handler, causing panics during requests, which is bad, especially when the response is gzipped: the next recover() is beyond the gzip handler, so the browser downloads a gz file instead.
parent b1e1caba
......@@ -113,8 +113,11 @@ func (h ErrorHandler) errorPage(w http.ResponseWriter, code int) {
http.Error(w, defaultBody, code)
}
func parse(c middleware.Controller) (ErrorHandler, error) {
handler := ErrorHandler{ErrorPages: make(map[int]string)}
func parse(c middleware.Controller) (*ErrorHandler, error) {
// Very important that we make a pointer because the Startup
// function that opens the log file must have access to the
// same instance of the handler, not a copy.
handler := &ErrorHandler{ErrorPages: make(map[int]string)}
optionalBlock := func() (bool, error) {
var hadBlock bool
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment