outposts/proxy: show full error message when user is authenticated

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-10-02 22:00:37 +02:00
parent 3c1ac4c7ec
commit f6e8dbfb5e
2 changed files with 7 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package application
import (
"fmt"
"html/template"
"net/http"
@ -8,8 +9,9 @@ import (
)
// NewProxyErrorHandler creates a ProxyErrorHandler using the template given.
func NewProxyErrorHandler(errorTemplate *template.Template) func(http.ResponseWriter, *http.Request, error) {
func (a *Application) newProxyErrorHandler(errorTemplate *template.Template) func(http.ResponseWriter, *http.Request, error) {
return func(rw http.ResponseWriter, req *http.Request, proxyErr error) {
claims, _ := a.getClaims(req)
log.WithError(proxyErr).Warning("Error proxying to upstream server")
rw.WriteHeader(http.StatusBadGateway)
data := struct {
@ -21,6 +23,9 @@ func NewProxyErrorHandler(errorTemplate *template.Template) func(http.ResponseWr
Message: "Error proxying to upstream server",
ProxyPrefix: "/akprox",
}
if claims != nil {
data.Message = fmt.Sprintf("Error proxying to upstream server: %s", proxyErr.Error())
}
err := errorTemplate.Execute(rw, data)
if err != nil {
http.Error(rw, "Internal Server Error", http.StatusInternalServerError)

View File

@ -29,7 +29,7 @@ func (a *Application) configureProxy() error {
}
rp := &httputil.ReverseProxy{Director: a.proxyModifyRequest(u)}
rp.Transport = ak.NewTracingTransport(context.TODO(), a.getUpstreamTransport())
rp.ErrorHandler = NewProxyErrorHandler(templates.GetTemplates())
rp.ErrorHandler = a.newProxyErrorHandler(templates.GetTemplates())
rp.ModifyResponse = a.proxyModifyResponse
a.mux.PathPrefix("/").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
claims, err := a.getClaims(r)