Log when remote file is not available

master
Yohan Boniface 2018-01-30 14:00:43 +01:00
parent a8ae4dcbdc
commit 25f165d74e
1 changed files with 10 additions and 4 deletions

View File

@ -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)