Abort on error, bar will be properly recreated

dev
Manuel Bua 2020-07-06 00:09:58 +02:00
parent d7b440a4ac
commit 6f894b718a
2 changed files with 10 additions and 0 deletions

View File

@ -66,6 +66,10 @@ func (p *Progress) Update() {
p.bar.Increment()
}
func (p *Progress) Abort() {
p.bar.Abort(true)
}
func (p *Progress) Wait() {
p.progress.Wait()
}

View File

@ -105,6 +105,7 @@ func (e *HTTPExecutor) ExecuteHTTP(p *progress.Progress, URL string) error {
mainLoop:
for compiledRequest := range compiledRequest {
if compiledRequest.Error != nil {
p.Abort()
return errors.Wrap(err, "error in compiled http request")
}
e.setCustomHeaders(compiledRequest)
@ -117,6 +118,7 @@ mainLoop:
dumpedRequest, err := httputil.DumpRequest(req.Request, true)
if err != nil {
p.Abort()
return errors.Wrap(err, "could not dump http request")
}
p.StartStdCapture()
@ -129,6 +131,7 @@ mainLoop:
if resp != nil {
resp.Body.Close()
}
p.Abort()
return errors.Wrap(err, "could not issue http request")
}
@ -139,6 +142,7 @@ mainLoop:
dumpedResponse, err := httputil.DumpResponse(resp, true)
if err != nil {
p.Abort()
return errors.Wrap(err, "could not dump http response")
}
p.StartStdCapture()
@ -150,6 +154,7 @@ mainLoop:
if err != nil {
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
p.Abort()
return errors.Wrap(err, "could not read http body")
}
resp.Body.Close()
@ -158,6 +163,7 @@ mainLoop:
// so in case we have to manually do it
data, err = requests.HandleDecompression(compiledRequest.Request, data)
if err != nil {
p.Abort()
return errors.Wrap(err, "could not decompress http body")
}