@@ -154,9 +154,28 @@ func NewReverseProxy(target *url.URL, opts *options.Options) (proxy *httputil.Re
154154 TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
155155 }
156156 }
157+ setProxyErrorHandler(proxy, opts)
157158 return proxy
158159}
159160
161+func setProxyErrorHandler(proxy *httputil.ReverseProxy, opts *options.Options) {
162+ templates := loadTemplates(opts.CustomTemplatesDir)
163+ proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, proxyErr error) {
164+ logger.Printf("Error proxying to upstream server: %v", proxyErr)
165+ w.WriteHeader(http.StatusBadGateway)
166+ data := struct {
167+ Title string
168+ Message string
169+ ProxyPrefix string
170+ }{
171+ Title: "Bad Gateway",
172+ Message: "Error proxying to upstream server",
173+ ProxyPrefix: opts.ProxyPrefix,
174+ }
175+ templates.ExecuteTemplate(w, "error.html", data)
176+ }
177+}
178+
160179func setProxyUpstreamHostHeader(proxy *httputil.ReverseProxy, target *url.URL) {
161180 director := proxy.Director
162181 proxy.Director = func(req *http.Request) {