diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-06-30 21:51:13 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-06-30 21:51:13 (GMT) |
commit | 870a7d2dbfe3d80738305781217e0610c64450db (patch) | |
tree | 047284973073455647fa9a9b5f023fa51449da83 | |
parent | 55008800e4e257ca3be55ae312fe6e94d6823d2a (diff) |
handle http status codes from curl
-rw-r--r-- | rhimport/fetcher.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go index 324ee5d..b78ea02 100644 --- a/rhimport/fetcher.go +++ b/rhimport/fetcher.go @@ -159,6 +159,13 @@ func fetchFileCurl(ctx *Context, res *Result, uri *url.URL) (err error) { easy.Setopt(curl.OPT_PROGRESSDATA, cbdata) err = easy.Perform() + statusCode := 0 + if curlResponseCode, err := easy.Getinfo(curl.INFO_RESPONSE_CODE); err == nil { + if code, ok := curlResponseCode.(int); ok { + statusCode = code + } + } + var convOut string var convErr error if cbdata.conv != nil { @@ -176,6 +183,11 @@ func fetchFileCurl(ctx *Context, res *Result, uri *url.URL) (err error) { rhl.Printf("download of '%s' got canceled", ctx.SourceUri) return nil } + if statusCode > 0 && statusCode != http.StatusOK { + res.ResponseCode = statusCode + res.ErrorString = fmt.Sprintf("non-OK response code (%d) while fetching the resource", statusCode) + return nil + } if cbdata.writeError != nil { err = cbdata.writeError } |