From 14a17540dfb9b0bf90401bf090da54ae491cb953 Mon Sep 17 00:00:00 2001 From: quiquelhappy Date: Mon, 16 Aug 2021 10:06:20 +0200 Subject: [PATCH] return more errors/info upon failed release downloads --- src/client/client.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/client/client.go b/src/client/client.go index fb0f626..fcacda6 100644 --- a/src/client/client.go +++ b/src/client/client.go @@ -4,6 +4,7 @@ import ( "archive/zip" "bytes" "encoding/json" + "errors" "fmt" "github.com/grifpkg/cli/config" "github.com/segmentio/ksuid" @@ -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) @@ -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()