-
Notifications
You must be signed in to change notification settings - Fork 886
fix: improve wsproxy error when proxyurl is set to a primary #11586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
In this stack:
This stack of pull requests is managed by Graphite. Learn more about stacking. |
7c82247
to
9656c7a
Compare
isCoderErr := fmt.Errorf("proxy url %q is not a coder proxy instance, verify the url is correct", reqURL) | ||
if resp.Header.Get(codersdk.BuildVersionHeader) != "" { | ||
isCoderErr = fmt.Errorf("proxy url %q is a coder instance, but unable to decode the response payload. Could this be a primary coderd and not a proxy?", reqURL) | ||
} | ||
|
||
// If the response is not json, then the user likely input a bad url that returns status code 200. | ||
// This is very common, since most webpages do return a 200. So let's improve the error message. | ||
if notJsonErr := codersdk.ExpectJSONMime(resp); notJsonErr != nil { | ||
|
||
err = errors.Join( | ||
isCoderErr, | ||
fmt.Errorf("attempted to query health at %q but got back the incorrect content type: %w", reqURL, notJsonErr), | ||
) | ||
|
||
status.Report.Errors = []string{ | ||
err.Error(), | ||
} | ||
status.Status = Unhealthy | ||
break | ||
} | ||
|
||
// If we cannot read the report, mark the proxy as unhealthy. | ||
status.Report.Errors = []string{fmt.Sprintf("failed to decode health report: %s", err.Error())} | ||
status.Report.Errors = []string{ | ||
errors.Join( | ||
isCoderErr, | ||
fmt.Errorf("received a status code 200, but failed to decode health report body: %w", err.Error()), | ||
).Error(), | ||
} | ||
status.Status = Unhealthy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The json decode error is usually absolute garbage. So this should improve it.
It also does a header check to instantly tell the user if they are not even pointed at a coder instance at all (proxy or otherwise)
fixes: #11116
Check header for proxy instance, and check content-type for non json. If it's not a json payload, the json error is almost completely useless.
I think this could be formatted better, but it has the helpful information, which is enough for now imo.