2021-09-08 18:04:56 +00:00
|
|
|
package application
|
|
|
|
|
|
|
|
import (
|
2021-10-02 20:00:37 +00:00
|
|
|
"fmt"
|
2021-09-08 18:04:56 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2021-12-20 21:20:23 +00:00
|
|
|
type ErrorPageData struct {
|
|
|
|
Title string
|
|
|
|
Message string
|
|
|
|
ProxyPrefix string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Application) ErrorPage(rw http.ResponseWriter, r *http.Request, err string) {
|
|
|
|
claims, _ := a.getClaims(r)
|
|
|
|
data := ErrorPageData{
|
|
|
|
Title: "Bad Gateway",
|
|
|
|
Message: "Error proxying to upstream server",
|
2022-02-08 19:25:38 +00:00
|
|
|
ProxyPrefix: "/outpost.goauthentik.io",
|
2021-12-20 21:20:23 +00:00
|
|
|
}
|
2022-07-30 18:29:23 +00:00
|
|
|
if claims != nil && claims.Proxy.IsSuperuser {
|
2021-12-20 21:20:23 +00:00
|
|
|
data.Message = err
|
2022-07-30 18:29:23 +00:00
|
|
|
} else {
|
|
|
|
data.Message = "Failed to connect to backend."
|
2021-12-20 21:20:23 +00:00
|
|
|
}
|
|
|
|
er := a.errorTemplates.Execute(rw, data)
|
|
|
|
if er != nil {
|
|
|
|
http.Error(rw, "Internal Server Error", http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-08 18:04:56 +00:00
|
|
|
// NewProxyErrorHandler creates a ProxyErrorHandler using the template given.
|
2021-12-20 21:20:23 +00:00
|
|
|
func (a *Application) newProxyErrorHandler() func(http.ResponseWriter, *http.Request, error) {
|
2021-09-08 18:04:56 +00:00
|
|
|
return func(rw http.ResponseWriter, req *http.Request, proxyErr error) {
|
2021-09-15 10:23:14 +00:00
|
|
|
log.WithError(proxyErr).Warning("Error proxying to upstream server")
|
2021-09-08 18:04:56 +00:00
|
|
|
rw.WriteHeader(http.StatusBadGateway)
|
2022-07-30 18:29:23 +00:00
|
|
|
a.ErrorPage(rw, req, fmt.Sprintf("Error proxying to upstream server: %v", proxyErr))
|
2021-09-08 18:04:56 +00:00
|
|
|
}
|
|
|
|
}
|