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 -5
View File
@@ -2,7 +2,6 @@ package codersdk
import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
@@ -143,7 +142,7 @@ func (c *Client) ExternalAuthDeviceByID(ctx context.Context, provider string) (E
return ExternalAuthDevice{}, ReadBodyAsError(res)
}
var extAuth ExternalAuthDevice
return extAuth, json.NewDecoder(res.Body).Decode(&extAuth)
return extAuth, ReadBodyAsJSON(res, &extAuth)
}
// ExchangeGitAuth exchanges a device code for an external auth token.
@@ -170,7 +169,7 @@ func (c *Client) ExternalAuthByID(ctx context.Context, provider string) (Externa
return ExternalAuth{}, ReadBodyAsError(res)
}
var extAuth ExternalAuth
return extAuth, json.NewDecoder(res.Body).Decode(&extAuth)
return extAuth, ReadBodyAsJSON(res, &extAuth)
}
// UnlinkExternalAuthByID deletes the external auth for the given provider by ID
@@ -186,7 +185,7 @@ func (c *Client) UnlinkExternalAuthByID(ctx context.Context, provider string) (D
return noRevoke, ReadBodyAsError(res)
}
var resp DeleteExternalAuthByIDResponse
err = json.NewDecoder(res.Body).Decode(&resp)
err = ReadBodyAsJSON(res, &resp)
if err != nil {
return noRevoke, err
}
@@ -205,5 +204,5 @@ func (c *Client) ListExternalAuths(ctx context.Context) (ListUserExternalAuthRes
return ListUserExternalAuthResponse{}, ReadBodyAsError(res)
}
var extAuth ListUserExternalAuthResponse
return extAuth, json.NewDecoder(res.Body).Decode(&extAuth)
return extAuth, ReadBodyAsJSON(res, &extAuth)
}