ch8.2
This commit is contained in:
@@ -43,3 +43,8 @@ func (app *application) badRequestResponse(w http.ResponseWriter, r *http.Reques
|
||||
func (app *application) failedValidationResponse(w http.ResponseWriter, r *http.Request, errors map[string]string) {
|
||||
app.errorResponse(w, r, http.StatusUnprocessableEntity, errors)
|
||||
}
|
||||
|
||||
func (app *application) editConflictResponse(w http.ResponseWriter, r *http.Request) {
|
||||
message := "unable to update the record due to an edit conflict, please try again"
|
||||
app.errorResponse(w, r, http.StatusConflict, message)
|
||||
}
|
||||
|
||||
@@ -127,7 +127,12 @@ func (app *application) updateMovieHandler(w http.ResponseWriter, r *http.Reques
|
||||
|
||||
err = app.models.Movies.Update(movie)
|
||||
if err != nil {
|
||||
app.serverErrorResponse(w, r, err)
|
||||
switch {
|
||||
case errors.Is(err, data.ErrEditConflict):
|
||||
app.editConflictResponse(w, r)
|
||||
default:
|
||||
app.serverErrorResponse(w, r, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user