Skip to content

Commit f89b680

Browse files
authored
chore: add debug information to wsproxy errors (#9683)
* chore: add debug information to wsproxy errors * Use codersdk.ReadBodyAsError
1 parent ae1896f commit f89b680

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

enterprise/coderd/proxyhealth/proxyhealth.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,27 @@ func (p *ProxyHealth) runOnce(ctx context.Context, now time.Time) (map[uuid.UUID
289289
case err == nil && resp.StatusCode != http.StatusOK:
290290
// Unhealthy as we did reach the proxy but it got an unexpected response.
291291
status.Status = Unhealthy
292-
status.Report.Errors = []string{fmt.Sprintf("unexpected status code %d", resp.StatusCode)}
292+
var builder strings.Builder
293+
// This string is shown on the UI where newlines are respected.
294+
// This error message is not ever decoded programmatically, so keep it human-
295+
// readable.
296+
builder.WriteString(fmt.Sprintf("unexpected status code %d. ", resp.StatusCode))
297+
builder.WriteString(fmt.Sprintf("\nEncountered error, send a request to %q from the Coderd environment to debug this issue.", reqURL))
298+
err := codersdk.ReadBodyAsError(resp)
299+
if err != nil {
300+
var apiErr *codersdk.Error
301+
if xerrors.As(err, &apiErr) {
302+
builder.WriteString(fmt.Sprintf("\nError Message: %s\nError Detail: %s", apiErr.Message, apiErr.Detail))
303+
for _, v := range apiErr.Validations {
304+
// Pretty sure this is not possible from the called endpoint, but just in case.
305+
builder.WriteString(fmt.Sprintf("\n\tValidation: %s=%s", v.Field, v.Detail))
306+
}
307+
} else {
308+
builder.WriteString(fmt.Sprintf("\nError: %s", err.Error()))
309+
}
310+
}
311+
312+
status.Report.Errors = []string{builder.String()}
293313
case err != nil:
294314
// Request failed, mark the proxy as unreachable.
295315
status.Status = Unreachable

0 commit comments

Comments
 (0)