mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2026-10-18 22:41:04 +02:00
render error page on 502 proxy status (#574)
Co-authored-by: Amnay Mokhtari <amnay.mokhtari@adevinta.com>
This commit is contained in:
@@ -154,9 +154,28 @@ func NewReverseProxy(target *url.URL, opts *options.Options) (proxy *httputil.Re
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
}
|
||||
setProxyErrorHandler(proxy, opts)
|
||||
return proxy
|
||||
}
|
||||
|
||||
func setProxyErrorHandler(proxy *httputil.ReverseProxy, opts *options.Options) {
|
||||
templates := loadTemplates(opts.CustomTemplatesDir)
|
||||
proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, proxyErr error) {
|
||||
logger.Printf("Error proxying to upstream server: %v", proxyErr)
|
||||
w.WriteHeader(http.StatusBadGateway)
|
||||
data := struct {
|
||||
Title string
|
||||
Message string
|
||||
ProxyPrefix string
|
||||
}{
|
||||
Title: "Bad Gateway",
|
||||
Message: "Error proxying to upstream server",
|
||||
ProxyPrefix: opts.ProxyPrefix,
|
||||
}
|
||||
templates.ExecuteTemplate(w, "error.html", data)
|
||||
}
|
||||
}
|
||||
|
||||
func setProxyUpstreamHostHeader(proxy *httputil.ReverseProxy, target *url.URL) {
|
||||
director := proxy.Director
|
||||
proxy.Director = func(req *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user