Have nicer 404 errors for covers

This commit is contained in:
2016-01-25 16:13:29 +01:00
parent ab1e7c7e91
commit f4c30e2b0e
2 changed files with 14 additions and 1 deletions

View File

@@ -20,6 +20,12 @@ type AlbumCoverCache struct {
TTL time.Duration
}
type ErrorNotRegistered AlbumID
func (e ErrorNotRegistered) Error() string {
return fmt.Sprintf("Cover URL for Album %d is not registered", AlbumID(e))
}
// NewAlbumCoverCache is creating a new cache at specified location on the fs
func NewAlbumCoverCache(basepath string, maxRequest uint, window time.Duration) *AlbumCoverCache {
res := &AlbumCoverCache{
@@ -37,7 +43,7 @@ func NewAlbumCoverCache(basepath string, maxRequest uint, window time.Duration)
func (c *AlbumCoverCache) fetch(ID AlbumID) (io.ReadCloser, string, error) {
URL, ok := c.URLs[ID]
if ok == false {
return nil, "", fmt.Errorf("Cover URL for Album %d is not registered", ID)
return nil, "", ErrorNotRegistered(ID)
}
ext := AlbumCoverExt(URL)