Skip to content

Commit

Permalink
Add 200 checks on web requests
Browse files Browse the repository at this point in the history
  • Loading branch information
xackery committed Feb 9, 2023
1 parent ccb2eef commit 5ebed9a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ func (c *Client) fetchFileList() error {
return fmt.Errorf("download %s: %w", url, err)
}
}
if resp.StatusCode != 200 {
c.cacheFileList = &FileList{}
return fmt.Errorf("download %s responded %d (not 200)", url, resp.StatusCode)
}

defer resp.Body.Close()
fileList := &FileList{}
Expand Down Expand Up @@ -213,6 +217,10 @@ func (c *Client) selfUpdate() error {
return fmt.Errorf("download %s: %w", url, err)
}

if resp.StatusCode != 200 {
return fmt.Errorf("download %s responded %d (not 200)", url, resp.StatusCode)
}

data, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
Expand Down Expand Up @@ -240,6 +248,9 @@ func (c *Client) selfUpdate() error {
return fmt.Errorf("get: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return fmt.Errorf("download %s responded %d (not 200)", url, resp.StatusCode)
}
c.logf("Applying update (will be used next launch)")
err = selfupdate.Apply(resp.Body, selfupdate.Options{})
if err != nil {
Expand Down

0 comments on commit 5ebed9a

Please sign in to comment.