From 41145a68425b3f6d1ca7ccff2a460ff3c6053eaf Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Wed, 18 Jan 2023 16:03:11 -0600 Subject: [PATCH] fix: improve error handling when posting workspace agent version (#5775) A customer ran into an unfortunate error here that we miss! --- codersdk/workspaceagents.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/codersdk/workspaceagents.go b/codersdk/workspaceagents.go index bb8ce62406..93ac907ab4 100644 --- a/codersdk/workspaceagents.go +++ b/codersdk/workspaceagents.go @@ -489,15 +489,15 @@ func (c *Client) PostWorkspaceAgentAppHealth(ctx context.Context, req PostWorksp } func (c *Client) PostWorkspaceAgentVersion(ctx context.Context, version string) error { - // Phone home and tell the mothership what version we're on. versionReq := PostWorkspaceAgentVersionRequest{Version: version} res, err := c.Request(ctx, http.MethodPost, "/api/v2/workspaceagents/me/version", versionReq) if err != nil { + return err + } + defer res.Body.Close() + if res.StatusCode != http.StatusOK { return readBodyAsError(res) } - // Discord the response - _, _ = io.Copy(io.Discard, res.Body) - _ = res.Body.Close() return nil }