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
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 52s
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user