Using the new error's helper methods inside our current API endpoint and with our httprouter Handlers NotFound and MethodNotAllowed (will override the default responses with our helper's methods)
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 52s

This commit is contained in:
Maxime Delporte
2025-10-21 19:02:42 +02:00
parent 0f7515e198
commit 2124f2f882
3 changed files with 12 additions and 5 deletions

View File

@@ -17,7 +17,8 @@ func (app *application) showMovieHandler(w http.ResponseWriter, r *http.Request)
id, err := app.readIDParam(r)
if err != nil || id < 1 {
http.NotFound(w, r)
// Use the new notFoundResponse() helper
app.notFoundResponse(w, r)
return
}
@@ -38,7 +39,7 @@ func (app *application) showMovieHandler(w http.ResponseWriter, r *http.Request)
// Encode the struct to JSON and send it as the HTTP response.
err = app.writeJSON(w, http.StatusOK, envelope{"movie": movie}, nil)
if err != nil {
app.logger.Error(err.Error())
http.Error(w, "The server encountered a problem and could not process your request", http.StatusInternalServerError)
// Use the new serverErrorResponse() helper
app.serverErrorResponse(w, r, err)
}
}