Creating badRequestResponse helper method inside errors.go and use in in the createMovieHandler.
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 53s
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 53s
This commit is contained in:
@@ -21,6 +21,7 @@ func (app *application) errorResponse(w http.ResponseWriter, r *http.Request, st
|
||||
|
||||
// Write the response using the writeJSON() helper. If this happens to return an error then og it, and fall back to sending the client an empty response with a 500 Internal Server Error status code.
|
||||
err := app.writeJSON(w, status, env, nil)
|
||||
|
||||
if err != nil {
|
||||
app.logError(r, err)
|
||||
w.WriteHeader(500)
|
||||
@@ -46,3 +47,7 @@ func (app *application) methodNotAllowedResponse(w http.ResponseWriter, r *http.
|
||||
message := fmt.Sprintf("the %s method is not supported for this resource", r.Method)
|
||||
app.errorResponse(w, r, http.StatusMethodNotAllowed, message)
|
||||
}
|
||||
|
||||
func (app *application) badRequestResponse(w http.ResponseWriter, r *http.Request, err error) {
|
||||
app.errorResponse(w, r, http.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user