Adding more context for invalidUnmarshalError management inside readJSON function. Updating 'Panicking vs returning errors' section.
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 54s
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 54s
This commit is contained in:
@@ -115,6 +115,7 @@ func (app *application) readJSON(w http.ResponseWriter, r *http.Request, dst any
|
||||
return errors.New("body must not be empty")
|
||||
|
||||
// A json.InvalidUnmarshalError error will be returned if we pass something that is not a non-nil pointer to Decode(). We catch this and panic, rather than returning an error to our handler.
|
||||
// This is firmly an unexpected error which we shouldn't see under normal operation, and is something that should be picked up in development and tests long before deployment.
|
||||
case errors.As(err, &invalidUnmarshalError):
|
||||
panic(err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user