fix handling of not found
This commit is contained in:
parent
522148254a
commit
d4f96c6cde
|
@ -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) {
|
func (api *MovieAPI) Delete(w http.ResponseWriter, r *http.Request, urlID string) {
|
||||||
logger := api.logger.With("method", "delete")
|
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)
|
Error(w, http.StatusInternalServerError, "could not delete movie", err, logger)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ WHERE id=?`, id)
|
||||||
}
|
}
|
||||||
var directors string
|
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 {
|
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, ",")
|
m.Directors = strings.Split(directors, ",")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue