refactor(codersdk): use ReadBodyAsJSON in typed endpoints (#27857)

This PR migrates 224 typed JSON response sites across 46 files to
`codersdk.ReadBodyAsJSON`, so invalid 2xx bodies return structured
errors while preserving URL credential redaction.

It intentionally excludes agent-direct HTTP, Azure IMDS, `UseNumber`,
and chat paths; stacked on coder/coder#27804, with chat and lint
follow-ups in coder/coder#27858 and coder/coder#27859. Refs
coder/coder#27044.

Reviewed and updated by Coder Agents on behalf of @dylanhuff-at-coder.
This commit is contained in:
dylanhuff-at-coder
2026-08-05 13:22:23 -07:00
committed by GitHub
parent 0c88c2accc
commit 76ae64391a
46 changed files with 224 additions and 257 deletions
+4 -4
View File
@@ -85,7 +85,7 @@ func (c *Client) GitSSHKey(ctx context.Context) (GitSSHKey, error) {
}
var gitSSHKey GitSSHKey
return gitSSHKey, json.NewDecoder(res.Body).Decode(&gitSSHKey)
return gitSSHKey, codersdk.ReadBodyAsJSON(res, &gitSSHKey)
}
type Metadata struct {
@@ -716,7 +716,7 @@ func (c *Client) PostLogSource(ctx context.Context, req PostLogSourceRequest) (c
return codersdk.WorkspaceAgentLogSource{}, codersdk.ReadBodyAsError(res)
}
var logSource codersdk.WorkspaceAgentLogSource
return logSource, json.NewDecoder(res.Body).Decode(&logSource)
return logSource, codersdk.ReadBodyAsJSON(res, &logSource)
}
type ExternalAuthResponse struct {
@@ -787,7 +787,7 @@ func (c *Client) ExternalAuth(ctx context.Context, req ExternalAuthRequest) (Ext
}
var authResp ExternalAuthResponse
return authResp, json.NewDecoder(res.Body).Decode(&authResp)
return authResp, codersdk.ReadBodyAsJSON(res, &authResp)
}
// LogsNotifyChannel returns the channel name responsible for notifying
@@ -1016,5 +1016,5 @@ func (c *Client) RefreshChatContext(ctx context.Context) (RefreshChatContextResp
}
var resp RefreshChatContextResponse
return resp, json.NewDecoder(res.Body).Decode(&resp)
return resp, codersdk.ReadBodyAsJSON(res, &resp)
}
+1 -2
View File
@@ -2,7 +2,6 @@ package agentsdk
import (
"context"
"encoding/json"
"io"
"net/http"
@@ -100,5 +99,5 @@ func (a *AWSSessionTokenExchanger) exchange(ctx context.Context) (AuthenticateRe
return AuthenticateResponse{}, codersdk.ReadBodyAsError(res)
}
var resp AuthenticateResponse
return resp, json.NewDecoder(res.Body).Decode(&resp)
return resp, codersdk.ReadBodyAsJSON(res, &resp)
}
+1 -1
View File
@@ -63,5 +63,5 @@ func (a *AzureSessionTokenExchanger) exchange(ctx context.Context) (Authenticate
return AuthenticateResponse{}, codersdk.ReadBodyAsError(res)
}
var resp AuthenticateResponse
return resp, json.NewDecoder(res.Body).Decode(&resp)
return resp, codersdk.ReadBodyAsJSON(res, &resp)
}
+1 -2
View File
@@ -2,7 +2,6 @@ package agentsdk
import (
"context"
"encoding/json"
"fmt"
"net/http"
@@ -75,5 +74,5 @@ func (g *GoogleSessionTokenExchanger) exchange(ctx context.Context) (Authenticat
return AuthenticateResponse{}, codersdk.ReadBodyAsError(res)
}
var resp AuthenticateResponse
return resp, json.NewDecoder(res.Body).Decode(&resp)
return resp, codersdk.ReadBodyAsJSON(res, &resp)
}