fix: handle empty data set
This commit is contained in:
parent
a60c7b91cc
commit
19ca25eb5b
|
@ -45,7 +45,12 @@ func GetRandomJokeFromCache(memory *cache.Cache) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
random := rand.Intn(len(data))
|
dataLength := len(data)
|
||||||
|
if dataLength == 0 {
|
||||||
|
return "", models.ErrEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
random := rand.Intn(dataLength)
|
||||||
joke := data[random].Link
|
joke := data[random].Link
|
||||||
|
|
||||||
return joke, nil
|
return joke, nil
|
||||||
|
|
|
@ -7,3 +7,4 @@ var ErrConnDone = errors.New("connection is already closed")
|
||||||
var ErrTxDone = errors.New("transaction has already been committed or rolled back")
|
var ErrTxDone = errors.New("transaction has already been committed or rolled back")
|
||||||
|
|
||||||
var ErrNotFound = errors.New("record not found")
|
var ErrNotFound = errors.New("record not found")
|
||||||
|
var ErrEmpty = errors.New("record is empty")
|
||||||
|
|
Loading…
Reference in New Issue