RenderStaticErrorPage renders the static error page. This is used by app requests to avoid dependence on the dashboard but maintain the ability to render a friendly error page on subdomains.
(rw http.ResponseWriter, r *http.Request, data ErrorPageData)
| 719 | // requests to avoid dependence on the dashboard but maintain the ability to |
| 720 | // render a friendly error page on subdomains. |
| 721 | func RenderStaticErrorPage(rw http.ResponseWriter, r *http.Request, data ErrorPageData) { |
| 722 | type outerData struct { |
| 723 | Error ErrorPageData |
| 724 | |
| 725 | ErrorDescriptionHTML htmltemplate.HTML |
| 726 | } |
| 727 | |
| 728 | rw.Header().Set("Content-Type", "text/html; charset=utf-8") |
| 729 | rw.WriteHeader(data.Status) |
| 730 | |
| 731 | err := errorTemplate.Execute(rw, outerData{ |
| 732 | Error: data, |
| 733 | ErrorDescriptionHTML: htmltemplate.HTML(data.Description), //nolint:gosec // gosec thinks this is user-input, but it is from Coder deployment configuration. |
| 734 | }) |
| 735 | if err != nil { |
| 736 | httpapi.Write(r.Context(), rw, http.StatusInternalServerError, codersdk.Response{ |
| 737 | Message: "Failed to render error page: " + err.Error(), |
| 738 | Detail: fmt.Sprintf("Original error was: %d %s, %s", data.Status, data.Title, data.Description), |
| 739 | }) |
| 740 | return |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | func applicationNameOrDefault(cfg codersdk.AppearanceConfig) string { |
| 745 | if cfg.ApplicationName != "" { |