From 6cf3574dcdb5a1151ec5c037068dbbf2492269f3 Mon Sep 17 00:00:00 2001 From: Pascal Precht <445106+0x-r4bbit@users.noreply.github.com> Date: Wed, 8 Feb 2023 11:11:36 +0100 Subject: [PATCH] fix(api): ensure getFavoriteGifs doesn't error when response is empty --- services/gif/gif.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/services/gif/gif.go b/services/gif/gif.go index 793293bc5..bec3d93a7 100644 --- a/services/gif/gif.go +++ b/services/gif/gif.go @@ -149,11 +149,14 @@ func (api *API) GetFavoriteGifs() (favoriteGifs []Gif, err error) { if err != nil { return nil, err } + favoriteGifs = make([]Gif, 0) savedFavGifs := []Gif{} - err = json.Unmarshal(gifs, &savedFavGifs) - if err != nil { - return nil, err + if len(gifs) > 0 { + err = json.Unmarshal(gifs, &savedFavGifs) + if err != nil { + return nil, err + } + favoriteGifs = savedFavGifs } - favoriteGifs = savedFavGifs return favoriteGifs, nil }