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

This commit is contained in:
Maxime Delporte
2025-10-25 09:57:41 +02:00
parent 6d09a4f545
commit c3fdb40ae4
2 changed files with 5 additions and 0 deletions

View File

@@ -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)