fix(api): ensure getFavoriteGifs doesn't error when response is empty

This commit is contained in:
Pascal Precht 2023-02-08 11:11:36 +01:00 committed by r4bbit
parent 41654bf49d
commit 6cf3574dcd
1 changed files with 7 additions and 4 deletions

View File

@ -149,11 +149,14 @@ func (api *API) GetFavoriteGifs() (favoriteGifs []Gif, err error) {
if err != nil {
return nil, err
}
favoriteGifs = make([]Gif, 0)
savedFavGifs := []Gif{}
if len(gifs) > 0 {
err = json.Unmarshal(gifs, &savedFavGifs)
if err != nil {
return nil, err
}
favoriteGifs = savedFavGifs
}
return favoriteGifs, nil
}