소스 검색

internal/build: don't crash in DownloadFile when offline (#20595)

Felix Lange 5 년 전
부모
커밋
4cc89a5a32
1개의 변경된 파일4개의 추가작업 그리고 2개의 파일을 삭제
  1. 4 2
      internal/build/download.go

+ 4 - 2
internal/build/download.go

@@ -83,8 +83,10 @@ func (db *ChecksumDB) DownloadFile(url, dstPath string) error {
 	fmt.Printf("downloading from %s\n", url)
 
 	resp, err := http.Get(url)
-	if err != nil || resp.StatusCode != http.StatusOK {
-		return fmt.Errorf("download error: code %d, err %v", resp.StatusCode, err)
+	if err != nil {
+		return fmt.Errorf("download error: %v", err)
+	} else if resp.StatusCode != http.StatusOK {
+		return fmt.Errorf("download error: status %d", resp.StatusCode)
 	}
 	defer resp.Body.Close()
 	if err := os.MkdirAll(filepath.Dir(dstPath), 0755); err != nil {