From 870a7d2dbfe3d80738305781217e0610c64450db Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 30 Jun 2016 23:51:13 +0200 Subject: handle http status codes from curl 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 } -- cgit v0.10.2