mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -2,7 +2,6 @@ package workspacesdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -158,7 +157,7 @@ func (c *Client) AgentConnectionInfoGeneric(ctx context.Context) (AgentConnectio
|
||||
}
|
||||
|
||||
var connInfo AgentConnectionInfo
|
||||
return connInfo, json.NewDecoder(res.Body).Decode(&connInfo)
|
||||
return connInfo, codersdk.ReadBodyAsJSON(res, &connInfo)
|
||||
}
|
||||
|
||||
func (c *Client) AgentConnectionInfo(ctx context.Context, agentID uuid.UUID) (AgentConnectionInfo, error) {
|
||||
@@ -172,7 +171,7 @@ func (c *Client) AgentConnectionInfo(ctx context.Context, agentID uuid.UUID) (Ag
|
||||
}
|
||||
|
||||
var connInfo AgentConnectionInfo
|
||||
return connInfo, json.NewDecoder(res.Body).Decode(&connInfo)
|
||||
return connInfo, codersdk.ReadBodyAsJSON(res, &connInfo)
|
||||
}
|
||||
|
||||
// AgentConnFunc returns a new connection to the specified agent. If release is
|
||||
|
||||
Reference in New Issue
Block a user