fix(api): ensure getRecentGifs doesn't error when response is empty
Because the BLOB retrieved from the database can be empty, umarshalling the data into JSON causes an error. The API should simply return an empty list of there are no recent gifs.
This commit is contained in:
parent
dea21f440a
commit
41654bf49d
|
@ -131,12 +131,15 @@ func (api *API) GetRecentGifs() (recentGifs []Gif, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
recentGifs = make([]Gif, 0)
|
||||||
savedRecentGifs := []Gif{}
|
savedRecentGifs := []Gif{}
|
||||||
|
if len(gifs) > 0 {
|
||||||
err = json.Unmarshal(gifs, &savedRecentGifs)
|
err = json.Unmarshal(gifs, &savedRecentGifs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
recentGifs = savedRecentGifs
|
recentGifs = savedRecentGifs
|
||||||
|
}
|
||||||
return recentGifs, nil
|
return recentGifs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue