fix handling of not found

This commit is contained in:
Erik Winter 2023-12-25 12:06:02 +01:00
parent 522148254a
commit d4f96c6cde
2 changed files with 8 additions and 2 deletions

View File

@ -111,7 +111,13 @@ func (api *MovieAPI) Store(w http.ResponseWriter, r *http.Request, urlID string)
func (api *MovieAPI) Delete(w http.ResponseWriter, r *http.Request, urlID string) {
logger := api.logger.With("method", "delete")
if err := api.repo.Delete(urlID); err != nil {
err := api.repo.Delete(urlID)
switch {
case errors.Is(err, sql.ErrNoRows):
w.WriteHeader(http.StatusNotFound)
fmt.Fprint(w, `{"message":"not found"}`)
return
case err != nil:
Error(w, http.StatusInternalServerError, "could not delete movie", err, logger)
return
}

View File

@ -125,7 +125,7 @@ WHERE id=?`, id)
}
var directors string
if err := row.Scan(&m.ID, &m.TMDBID, &m.IMDBID, &m.Title, &m.EnglishTitle, &m.Year, &directors, &m.Summary, &m.WatchedOn, &m.Rating, &m.Comment); err != nil {
return nil, fmt.Errorf("%w: %v", ErrSqliteFailure, err)
return nil, fmt.Errorf("%w: %w", ErrSqliteFailure, err)
}
m.Directors = strings.Split(directors, ",")