Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9052920

Browse files
authored
fix: improve wsproxy error when proxyurl is set to a primary (#11586)
* coder error first
1 parent03ee639 commit9052920

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

‎enterprise/coderd/proxyhealth/proxyhealth.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package proxyhealth
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"net/http"
89
"net/url"
@@ -275,8 +276,33 @@ func (p *ProxyHealth) runOnce(ctx context.Context, now time.Time) (map[uuid.UUID
275276
caseerr==nil&&resp.StatusCode==http.StatusOK:
276277
err:=json.NewDecoder(resp.Body).Decode(&status.Report)
277278
iferr!=nil {
279+
isCoderErr:=fmt.Errorf("proxy url %q is not a coder proxy instance, verify the url is correct",reqURL)
280+
ifresp.Header.Get(codersdk.BuildVersionHeader)!="" {
281+
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)
282+
}
283+
284+
// If the response is not json, then the user likely input a bad url that returns status code 200.
285+
// This is very common, since most webpages do return a 200. So let's improve the error message.
286+
ifnotJSONErr:=codersdk.ExpectJSONMime(resp);notJSONErr!=nil {
287+
err=errors.Join(
288+
isCoderErr,
289+
fmt.Errorf("attempted to query health at %q but got back the incorrect content type: %w",reqURL,notJSONErr),
290+
)
291+
292+
status.Report.Errors= []string{
293+
err.Error(),
294+
}
295+
status.Status=Unhealthy
296+
break
297+
}
298+
278299
// If we cannot read the report, mark the proxy as unhealthy.
279-
status.Report.Errors= []string{fmt.Sprintf("failed to decode health report: %s",err.Error())}
300+
status.Report.Errors= []string{
301+
errors.Join(
302+
isCoderErr,
303+
fmt.Errorf("received a status code 200, but failed to decode health report body: %w",err),
304+
).Error(),
305+
}
280306
status.Status=Unhealthy
281307
break
282308
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp