Add logging if downloading an image from unsplash fails

This commit is contained in:
kolaente 2020-05-29 22:11:49 +02:00
parent 54b18b3c59
commit 42ddee8d6f
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -17,6 +17,7 @@
package unsplash package unsplash
import ( import (
"bytes"
"code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/files" "code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/log"
@ -200,6 +201,13 @@ func (p *Provider) Set(image *background.Image, list *models.List, auth web.Auth
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode > 399 {
b := bytes.Buffer{}
_, _ = b.ReadFrom(resp.Body)
log.Errorf("Error getting unsplash photo %s: Request failed with status %d, message was %s", photo.ID, resp.StatusCode, b.String())
return
}
log.Debugf("Downloaded Unsplash Photo %s", image.ID) log.Debugf("Downloaded Unsplash Photo %s", image.ID)
// Save it as a file in vikunja // Save it as a file in vikunja