Skip to content

Commit

Permalink
return more errors/info upon failed release downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
quiquelhappy committed Aug 16, 2021
1 parent 9d057cc commit 14a1754
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/zip"
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/grifpkg/cli/config"
"github.com/segmentio/ksuid"
Expand Down Expand Up @@ -61,13 +62,22 @@ func DownloadResource(resource Resource, version string, projectConfig config.Pr

// gets release
release, err := getRelease(resource,version)
if err != nil {
return DownloadableRelease{}, err
}

// gets downloadable release
request, err := request("resource/release/download/", map[string]string{
"release": release.Id,
})
downloadableRelease := DownloadableRelease{}
if err != nil {
return DownloadableRelease{}, err
}
err = json.NewDecoder(request).Decode(&downloadableRelease)
if err != nil {
return DownloadableRelease{}, errors.New("invalid JSON response from the server")
}

// download
finalPath, separator, basepath, err := downloadFile(downloadableRelease,projectConfig)
Expand All @@ -84,6 +94,10 @@ func DownloadResource(resource Resource, version string, projectConfig config.Pr
}

func downloadFile(downloadableRelease DownloadableRelease, projectConfig config.Project) (string, string, string, error){
if downloadableRelease.Url == "" {
return "", "", "", errors.New("this release is hosted externally. support for externally hosted releases is coming this week")
}

resp, err := http.Get(downloadableRelease.Url)
defer resp.Body.Close()

Expand Down

0 comments on commit 14a1754

Please sign in to comment.