func (e *errorPageWriter) ProxyErrorHandler(rw http.ResponseWriter, req *http.Request, proxyErr error) {
	logger.Errorf("Error proxying to upstream server: %v", proxyErr)
	scope := middlewareapi.GetRequestScope(req)
	e.WriteErrorPage(rw, ErrorPageOpts{
		Status:      http.StatusBadGateway,
		RedirectURL: "",  
		RequestID:   scope.RequestID,
		AppError:    proxyErr.Error(),
		Messages:    []interface{}{"There was a problem connecting to the upstream server."},
	})
}
ProxyErrorHandler is used by the upstream ReverseProxy to render error pages
when there are issues with upstream servers.
It is expected to always render a bad gateway error.
package pagewriter
import (
	"fmt"
	"html/template"
	"net/http"
	middlewareapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
)
var errorMessages = map[int]string{
	http.StatusInternalServerError: "Oops! Something went wrong. For more information contact your server administrator.",
	http.StatusNotFound:            "We could not find the resource you were looking for.",
	http.StatusForbidden:           "You do not have permission to access this resource.",
	http.StatusUnauthorized:        "You need to be logged in to access this resource.",
}
type errorPageWriter struct {
	template *template.Template
	proxyPrefix string
	footer string
	version string
	debug bool
}
type ErrorPageOpts struct {
	Status int
	RedirectURL string
	RequestID string
	AppError string
	Messages []interface{}
}
func (e *errorPageWriter) WriteErrorPage(rw http.ResponseWriter, opts ErrorPageOpts) {
	rw.WriteHeader(opts.Status)
	data := struct {
		Title       string
		Message     string
		ProxyPrefix string
		StatusCode  int
		Redirect    string
		RequestID   string
		Footer      template.HTML
		Version     string
	}{
		Title:       http.StatusText(opts.Status),
		Message:     e.getMessage(opts.Status, opts.AppError, opts.Messages...),
		ProxyPrefix: e.proxyPrefix,
		StatusCode:  opts.Status,
		Redirect:    opts.RedirectURL,
		RequestID:   opts.RequestID,
		Footer:      template.HTML(e.footer),
		Version:     e.version,
	}
	if err := e.template.Execute(rw, data); err != nil {
		logger.Printf("Error rendering error template: %v", err)
		http.Error(rw, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
	}
}