Skip to content

fix: refresh all oauth links on external auth page #11646

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

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
linting
  • Loading branch information
Emyrk committed Jan 16, 2024
commit d923cfc978fa3fea5b51ac16dbb22ff9cf6562da
4 changes: 4 additions & 0 deletions codersdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ func ExpectJSONMime(res *http.Response) error {

// ReadBodyAsError reads the response as a codersdk.Response, and
// wraps it in a codersdk.Error type for easy marshaling.
//
// This will always return an error, so only call it if the response failed
// your expectations. Usually via status code checking.
// nolint:staticcheck
func ReadBodyAsError(res *http.Response) error {
if res == nil {
return xerrors.Errorf("no body returned")
Expand Down
11 changes: 11 additions & 0 deletions codersdk/client_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ func Test_readBodyAsError(t *testing.T) {
assert.Equal(t, unexpectedJSON, sdkErr.Response.Detail)
},
},
{
// Even status code 200 should be considered an error if this function
// is called. There are parts of the code that require this function
// to always return an error.
name: "OKResp",
req: nil,
res: newResponse(http.StatusOK, jsonCT, marshal(map[string]any{})),
assert: func(t *testing.T, err error) {
require.Error(t, err)
},
},
}

for _, c := range tests {
Expand Down
18 changes: 8 additions & 10 deletions enterprise/coderd/proxyhealth/proxyhealth.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,17 @@ func (p *ProxyHealth) runOnce(ctx context.Context, now time.Time) (map[uuid.UUID
// readable.
builder.WriteString(fmt.Sprintf("unexpected status code %d. ", resp.StatusCode))
builder.WriteString(fmt.Sprintf("\nEncountered error, send a request to %q from the Coderd environment to debug this issue.", reqURL))
// err will always be non-nil
err := codersdk.ReadBodyAsError(resp)
if err != nil {
var apiErr *codersdk.Error
if xerrors.As(err, &apiErr) {
builder.WriteString(fmt.Sprintf("\nError Message: %s\nError Detail: %s", apiErr.Message, apiErr.Detail))
for _, v := range apiErr.Validations {
// Pretty sure this is not possible from the called endpoint, but just in case.
builder.WriteString(fmt.Sprintf("\n\tValidation: %s=%s", v.Field, v.Detail))
}
} else {
builder.WriteString(fmt.Sprintf("\nError: %s", err.Error()))
var apiErr *codersdk.Error
if xerrors.As(err, &apiErr) {
builder.WriteString(fmt.Sprintf("\nError Message: %s\nError Detail: %s", apiErr.Message, apiErr.Detail))
for _, v := range apiErr.Validations {
// Pretty sure this is not possible from the called endpoint, but just in case.
builder.WriteString(fmt.Sprintf("\n\tValidation: %s=%s", v.Field, v.Detail))
}
}
builder.WriteString(fmt.Sprintf("\nError: %s", err.Error()))

status.Report.Errors = []string{builder.String()}
case err != nil:
Expand Down