(title, heading string, sc int, configKey string)
| 11 | ) |
| 12 | |
| 13 | func (h *Handler) fallbackHandler(title, heading string, sc int, configKey string) func(w http.ResponseWriter, r *http.Request) { |
| 14 | if title == "" { |
| 15 | title = "The request could not be executed because a mandatory configuration key is missing or malformed" |
| 16 | } |
| 17 | |
| 18 | if heading == "" { |
| 19 | heading = "The request could not be executed because a mandatory configuration key is missing or malformed" |
| 20 | } |
| 21 | |
| 22 | return func(w http.ResponseWriter, r *http.Request) { |
| 23 | h.r.Logger().Errorf(`A request failed because configuration key "%s" is missing or malformed.`, configKey) |
| 24 | |
| 25 | t, err := template.New(configKey).Parse(`<html> |
| 26 | <head> |
| 27 | <title>{{ .Title }}</title> |
| 28 | </head> |
| 29 | <body> |
| 30 | <h1> |
| 31 | {{ .Heading }} |
| 32 | </h1> |
| 33 | <p> |
| 34 | You are seeing this page because configuration key <code>{{ .Key }}</code> is not set. |
| 35 | </p> |
| 36 | <p> |
| 37 | If you are an administrator, please read <a href="https://www.ory.sh/docs">the guide</a> to understand what you |
| 38 | need to do. If you are a user, please contact the administrator. |
| 39 | </p> |
| 40 | </body> |
| 41 | </html>`) |
| 42 | if err != nil { |
| 43 | h.r.Writer().WriteError(w, r, err) |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | w.WriteHeader(sc) |
| 48 | if err := t.Execute(w, struct { |
| 49 | Title string |
| 50 | Heading string |
| 51 | Key string |
| 52 | }{Title: title, Heading: heading, Key: configKey}); err != nil { |
| 53 | h.r.Writer().WriteError(w, r, err) |
| 54 | return |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func (h *Handler) DefaultErrorHandler(w http.ResponseWriter, r *http.Request) { |
| 60 | h.r.Logger().WithRequest(r).Error("A client requested the default error URL, environment variable URLS_ERROR is probably not set.") |
no test coverage detected