diff --git a/enterprise/wsproxy/wsproxy.go b/enterprise/wsproxy/wsproxy.go index 508167550d51c..f617f00c0581a 100644 --- a/enterprise/wsproxy/wsproxy.go +++ b/enterprise/wsproxy/wsproxy.go @@ -235,9 +235,11 @@ func New(ctx context.Context, opts *Options) (*Server, error) { r.Get("/healthz-report", s.healthReport) r.NotFound(func(rw http.ResponseWriter, r *http.Request) { site.RenderStaticErrorPage(rw, r, site.ErrorPageData{ - Status: 404, - Title: "Route Not Found", - Description: "The route you requested does not exist on this workspace proxy. Maybe you intended to make this request to the primary dashboard? Click below to be redirected to the primary site.", + Title: "Head to the Dashboard", + Status: http.StatusBadRequest, + HideStatus: true, + Description: "Workspace Proxies route traffic in terminals and apps directly to your workspace. " + + "This page must be loaded from the dashboard. Click to be redirected!", RetryEnabled: false, DashboardURL: opts.DashboardURL.String(), }) diff --git a/site/site.go b/site/site.go index 28f0880c3c381..e047ab21cb4d4 100644 --- a/site/site.go +++ b/site/site.go @@ -606,7 +606,9 @@ func extractBin(dest string, r io.Reader) (numExtracted int, err error) { // ErrorPageData contains the variables that are found in // site/static/error.html. type ErrorPageData struct { - Status int + Status int + // HideStatus will remove the status code from the page. + HideStatus bool Title string Description string RetryEnabled bool diff --git a/site/site_test.go b/site/site_test.go index c7b301982f71b..f06ce1f991e60 100644 --- a/site/site_test.go +++ b/site/site_test.go @@ -517,3 +517,34 @@ func TestRenderStaticErrorPage(t *testing.T) { require.Contains(t, bodyStr, "Retry") require.Contains(t, bodyStr, d.DashboardURL) } + +func TestRenderStaticErrorPageNoStatus(t *testing.T) { + t.Parallel() + + d := site.ErrorPageData{ + HideStatus: true, + Status: http.StatusBadGateway, + Title: "Bad Gateway 1234", + Description: "shout out colin", + RetryEnabled: true, + DashboardURL: "https://example.com", + } + + rw := httptest.NewRecorder() + r := httptest.NewRequest("GET", "/", nil) + site.RenderStaticErrorPage(rw, r, d) + + resp := rw.Result() + defer resp.Body.Close() + require.Equal(t, d.Status, resp.StatusCode) + require.Contains(t, resp.Header.Get("Content-Type"), "text/html") + + body, err := io.ReadAll(resp.Body) + require.NoError(t, err) + bodyStr := string(body) + require.NotContains(t, bodyStr, strconv.Itoa(d.Status)) + require.Contains(t, bodyStr, d.Title) + require.Contains(t, bodyStr, d.Description) + require.Contains(t, bodyStr, "Retry") + require.Contains(t, bodyStr, d.DashboardURL) +} diff --git a/site/static/error.html b/site/static/error.html index f587a63f467ed..93b348d4552f9 100644 --- a/site/static/error.html +++ b/site/static/error.html @@ -7,7 +7,10 @@ - {{ .Error.Status }} - {{ .Error.Title }} + + {{- if not .Error.HideStatus }}{{ .Error.Status }} - {{end}}{{ + .Error.Title }} +