diff --git a/cmd/stashcp/main.go b/cmd/stashcp/main.go index 2e099ff..6890219 100644 --- a/cmd/stashcp/main.go +++ b/cmd/stashcp/main.go @@ -245,7 +245,7 @@ func main() { if errMsg == "" { errMsg = result.Error() } - log.Errorln("Failure downloading " + lastSrc + ": " + errMsg) + log.Errorln("Failure transferring " + lastSrc + ": " + errMsg) if stashcp.ErrorsRetryable() { log.Errorln("Errors are retryable") os.Exit(11) diff --git a/errorAccum.go b/errorAccum.go index 0113dea..32fc48e 100644 --- a/errorAccum.go +++ b/errorAccum.go @@ -91,6 +91,18 @@ func IsRetryable(err error) bool { } return true } + var hep *HttpErrResp + if errors.As(err, &hep) { + switch int(hep.Code) { + case http.StatusInternalServerError: + case http.StatusBadGateway: + case http.StatusServiceUnavailable: + case http.StatusGatewayTimeout: + return true + default: + return false + } + } return false } diff --git a/handle_http.go b/handle_http.go index b5e1021..e243b8d 100644 --- a/handle_http.go +++ b/handle_http.go @@ -39,6 +39,16 @@ func (e *StoppedTransferError) Error() string { } +type HttpErrResp struct { + Code int + Err string +} + +func (e *HttpErrResp) Error() string { + return e.Err +} + + // SlowTransferError is an error that is returned when a transfer takes longer than the configured timeout type SlowTransferError struct { BytesTransferred int64 @@ -641,7 +651,8 @@ Loop: // prior attempt. if resp.HTTPResponse.StatusCode != 200 && resp.HTTPResponse.StatusCode != 206 { log.Debugln("Got failure status code:", resp.HTTPResponse.StatusCode) - return 0, errors.New("failure status code") + return 0, &HttpErrResp{resp.HTTPResponse.StatusCode, fmt.Sprintf("Request failed (HTTP status %d): %s", + resp.HTTPResponse.StatusCode, resp.Err().Error())} } log.Debugln("HTTP Transfer was successful") return resp.BytesComplete(), nil @@ -760,7 +771,8 @@ Loop: case response := <-responseChan: if response.StatusCode != 200 { log.Errorln("Got failure status code:", response.StatusCode) - lastError = errors.New("failure status code") + lastError = &HttpErrResp{response.StatusCode, fmt.Sprintf("Request failed (HTTP status %d)", + response.StatusCode)} break Loop } break Loop diff --git a/main.go b/main.go index 1062032..88e430a 100644 --- a/main.go +++ b/main.go @@ -334,8 +334,12 @@ func DoStashCPSingle(sourceFile string, destination string, methods []string, re ns, err := MatchNamespace(dest_url.Path) if err != nil { log.Errorln("Failed to get namespace information:", err) + AddError(err) + return 0, err } - return doWriteBack(source_url.Path, dest_url, ns) + _, err = doWriteBack(source_url.Path, dest_url, ns) + AddError(err) + return 0, err } if dest_url.Scheme == "file" {