Recovery Handler to prevent server from crashing

suggest change
func Recovery(h http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){
        defer func() {
            if err := recover(); err != nil {
                // respondInternalServerError
            }
        }()
        h.ServeHTTP(w, r)
    })
}

recover stops the panic in this goroutine. The deferred function should write a 500 response. If the handler has already written a status, that status cannot be replaced.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents