This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2021-09-08 18:04:56 +00:00
|
|
|
package application
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html/template"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewProxyErrorHandler creates a ProxyErrorHandler using the template given.
|
|
|
|
func NewProxyErrorHandler(errorTemplate *template.Template) func(http.ResponseWriter, *http.Request, error) {
|
|
|
|
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)
|
|
|
|
data := struct {
|
|
|
|
Title string
|
|
|
|
Message string
|
|
|
|
ProxyPrefix string
|
|
|
|
}{
|
|
|
|
Title: "Bad Gateway",
|
|
|
|
Message: "Error proxying to upstream server",
|
|
|
|
ProxyPrefix: "/akprox",
|
|
|
|
}
|
|
|
|
err := errorTemplate.Execute(rw, data)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(rw, "Internal Server Error", http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|