Skip to content

Commit

Permalink
refactor(crawler): handle sha1 fetch error before checking status (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen authored Jan 22, 2024
1 parent 184bd74 commit ee3f7e3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,16 @@ func (c *Crawler) parseMetadata(url string) (*Metadata, error) {

func (c *Crawler) fetchSHA1(url string) ([]byte, error) {
resp, err := c.http.Get(url)
// some projects don't have xxx.jar and xxx.jar.sha1 files
if resp.StatusCode == http.StatusNotFound {
return nil, nil // TODO add special error for this
}
if err != nil {
return nil, xerrors.Errorf("can't get sha1 from %s: %w", url, err)
}
defer resp.Body.Close()

// some projects don't have xxx.jar and xxx.jar.sha1 files
if resp.StatusCode == http.StatusNotFound {
return nil, nil // TODO add special error for this
}

sha1, err := io.ReadAll(resp.Body)
if err != nil {
return nil, xerrors.Errorf("can't read sha1 %s: %w", url, err)
Expand Down

0 comments on commit ee3f7e3

Please sign in to comment.