outposts/proxy: show full error message when user is authenticated
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
3c1ac4c7ec
commit
f6e8dbfb5e
|
@ -1,6 +1,7 @@
|
||||||
package application
|
package application
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
@ -8,8 +9,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewProxyErrorHandler creates a ProxyErrorHandler using the template given.
|
// 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) {
|
return func(rw http.ResponseWriter, req *http.Request, proxyErr error) {
|
||||||
|
claims, _ := a.getClaims(req)
|
||||||
log.WithError(proxyErr).Warning("Error proxying to upstream server")
|
log.WithError(proxyErr).Warning("Error proxying to upstream server")
|
||||||
rw.WriteHeader(http.StatusBadGateway)
|
rw.WriteHeader(http.StatusBadGateway)
|
||||||
data := struct {
|
data := struct {
|
||||||
|
@ -21,6 +23,9 @@ func NewProxyErrorHandler(errorTemplate *template.Template) func(http.ResponseWr
|
||||||
Message: "Error proxying to upstream server",
|
Message: "Error proxying to upstream server",
|
||||||
ProxyPrefix: "/akprox",
|
ProxyPrefix: "/akprox",
|
||||||
}
|
}
|
||||||
|
if claims != nil {
|
||||||
|
data.Message = fmt.Sprintf("Error proxying to upstream server: %s", proxyErr.Error())
|
||||||
|
}
|
||||||
err := errorTemplate.Execute(rw, data)
|
err := errorTemplate.Execute(rw, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(rw, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(rw, "Internal Server Error", http.StatusInternalServerError)
|
||||||
|
|
|
@ -29,7 +29,7 @@ func (a *Application) configureProxy() error {
|
||||||
}
|
}
|
||||||
rp := &httputil.ReverseProxy{Director: a.proxyModifyRequest(u)}
|
rp := &httputil.ReverseProxy{Director: a.proxyModifyRequest(u)}
|
||||||
rp.Transport = ak.NewTracingTransport(context.TODO(), a.getUpstreamTransport())
|
rp.Transport = ak.NewTracingTransport(context.TODO(), a.getUpstreamTransport())
|
||||||
rp.ErrorHandler = NewProxyErrorHandler(templates.GetTemplates())
|
rp.ErrorHandler = a.newProxyErrorHandler(templates.GetTemplates())
|
||||||
rp.ModifyResponse = a.proxyModifyResponse
|
rp.ModifyResponse = a.proxyModifyResponse
|
||||||
a.mux.PathPrefix("/").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
a.mux.PathPrefix("/").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||||
claims, err := a.getClaims(r)
|
claims, err := a.getClaims(r)
|
||||||
|
|
Reference in New Issue