1
0
Fork 0

Return 404 for empty database results.

Without this special handling we return a 500 instead.
main
Icedream 2024-01-22 00:26:55 +01:00
parent 7c4f45d8f5
commit f16e4579cb
Signed by: icedream
GPG Key ID: 468BBEEBB9EC6AEA
1 changed files with 8 additions and 0 deletions

View File

@ -285,6 +285,10 @@ func main() {
return
}
file, err := m.GetFile(uint(fileID))
if errors.Is(err, gorm.ErrRecordNotFound) {
c.JSON(http.StatusNotFound, err.Error())
return
}
if err != nil {
c.JSON(http.StatusInternalServerError, err.Error())
return
@ -310,6 +314,10 @@ func main() {
return
}
track, err := m.GetTrackByArtistAndTitle(form.Artist, form.Title, false)
if errors.Is(err, gorm.ErrRecordNotFound) {
c.JSON(http.StatusNotFound, err.Error())
return
}
if err != nil {
c.JSON(http.StatusInternalServerError, err.Error())
return