Creating validator.go allowing us to validate received data from our endpoints. Updating errors.go adding failedValidationResponse method allowing us to deliver a StatusUnprocessableEntity error. Updating createMovieHandler with the use of our new validator package.
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:
@@ -51,3 +51,8 @@ func (app *application) methodNotAllowedResponse(w http.ResponseWriter, r *http.
|
||||
func (app *application) badRequestResponse(w http.ResponseWriter, r *http.Request, err error) {
|
||||
app.errorResponse(w, r, http.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
// The errors parameter here has the type map[string]string, which is exactly the same as the errors map contained in our Validator type.
|
||||
func (app *application) failedValidationResponse(w http.ResponseWriter, r *http.Request, errors map[string]string) {
|
||||
app.errorResponse(w, r, http.StatusUnprocessableEntity, errors)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user