Skip to content

Commit 9656c7a

Browse files
committed
coder error first
1 parent f5a9f5c commit 9656c7a

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

enterprise/coderd/proxyhealth/proxyhealth.go

Lines changed: 28 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,34 @@ func (p *ProxyHealth) runOnce(ctx context.Context, now time.Time) (map[uuid.UUID
275276
case err == nil && resp.StatusCode == http.StatusOK:
276277
err := json.NewDecoder(resp.Body).Decode(&status.Report)
277278
if err != nil {
279+
isCoderErr := fmt.Errorf("proxy url %q is not a coder proxy instance, verify the url is correct", reqURL)
280+
if resp.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+
if notJsonErr := codersdk.ExpectJSONMime(resp); notJsonErr != nil {
287+
288+
err = errors.Join(
289+
isCoderErr,
290+
fmt.Errorf("attempted to query health at %q but got back the incorrect content type: %w", reqURL, notJsonErr),
291+
)
292+
293+
status.Report.Errors = []string{
294+
err.Error(),
295+
}
296+
status.Status = Unhealthy
297+
break
298+
}
299+
278300
// 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())}
301+
status.Report.Errors = []string{
302+
errors.Join(
303+
isCoderErr,
304+
fmt.Errorf("received a status code 200, but failed to decode health report body: %w", err.Error()),
305+
).Error(),
306+
}
280307
status.Status = Unhealthy
281308
break
282309
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy