From 25f165d74ee27b1038dc6f9d5053dc4f1868e183 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 30 Jan 2018 14:00:43 +0100 Subject: [PATCH] Log when remote file is not available --- replication/source.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/replication/source.go b/replication/source.go index 1d39caa..2a91ec1 100644 --- a/replication/source.go +++ b/replication/source.go @@ -19,7 +19,13 @@ import ( var log = logging.NewLogger("replication") -var NotAvailable = errors.New("file not available") +type NotAvailable struct { + url string +} + +func (e *NotAvailable) Error() string { + return fmt.Sprintf("File not available: %s", e.url) +} type Sequence struct { Filename string @@ -132,8 +138,7 @@ func (d *downloader) download(seq int, ext string) error { defer resp.Body.Close() if resp.StatusCode == 404 { - log.Print("Remote file does not exist ", url) - return NotAvailable + return &NotAvailable{url} } if resp.StatusCode != 200 { @@ -160,7 +165,8 @@ func (d *downloader) downloadTillSuccess(seq int, ext string) { if err == nil { break } - if err == NotAvailable { + if err, ok := err.(*NotAvailable); ok { + log.Print(err) time.Sleep(d.naWaittime) } else { log.Warn(err)