|
1 | 1 | package workspaceapps
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "net/http"
|
5 | 6 | "net/url"
|
6 | 7 |
|
7 | 8 | "cdr.dev/slog"
|
| 9 | + "github.com/coder/coder/v2/codersdk" |
8 | 10 | "github.com/coder/coder/v2/site"
|
9 | 11 | )
|
10 | 12 |
|
@@ -90,3 +92,28 @@ func WriteWorkspaceAppOffline(log slog.Logger, accessURL *url.URL, rw http.Respo
|
90 | 92 | DashboardURL: accessURL.String(),
|
91 | 93 | })
|
92 | 94 | }
|
| 95 | + |
| 96 | +// WriteWorkspaceOffline writes a HTML 400 error page for a workspace app. If |
| 97 | +// appReq is not nil, it will be used to log the request details at debug level. |
| 98 | +func WriteWorkspaceOffline(log slog.Logger, accessURL *url.URL, rw http.ResponseWriter, r *http.Request, appReq *Request) { |
| 99 | + if appReq != nil { |
| 100 | + slog.Helper() |
| 101 | + log.Debug(r.Context(), |
| 102 | + "workspace app unavailable: workspace stopped", |
| 103 | + slog.F("username_or_id", appReq.UsernameOrID), |
| 104 | + slog.F("workspace_and_agent", appReq.WorkspaceAndAgent), |
| 105 | + slog.F("workspace_name_or_id", appReq.WorkspaceNameOrID), |
| 106 | + slog.F("agent_name_or_id", appReq.AgentNameOrID), |
| 107 | + slog.F("app_slug_or_port", appReq.AppSlugOrPort), |
| 108 | + slog.F("hostname_prefix", appReq.Prefix), |
| 109 | + ) |
| 110 | + } |
| 111 | + |
| 112 | + site.RenderStaticErrorPage(rw, r, site.ErrorPageData{ |
| 113 | + Status: http.StatusBadRequest, |
| 114 | + Title: "Workspace Offline", |
| 115 | + Description: fmt.Sprintf("Last workspace transition was to the %q state. Start the workspace to access its applications.", codersdk.WorkspaceTransitionStop), |
| 116 | + RetryEnabled: false, |
| 117 | + DashboardURL: accessURL.String(), |
| 118 | + }) |
| 119 | +} |
0 commit comments