Documentation
¶
Overview ¶
errors.HandleErrorf: keep the classification, add the call site.
A domain sentinel says what went wrong ("plan not found") but not which resource. HandleErrorf wraps the error with %w and then handles it exactly like HandleError: the central map still recognizes the sentinel, so the status stays 404, while the rendered message carries the call-site detail and the original error travels in the response's data list (and the logs).
Learn: add call-site detail to a mapped error without changing the status code the central map chose for it. Before: ../central-error-map
Run:
go run main.go
Try:
curl -i http://localhost:8080/plans/starter # 200 curl -i http://localhost:8080/plans/42 # 404, message "plan with id: 42", the sentinel under "data" curl -i http://localhost:8080/plans/42/plain # 404, message is only "plan not found"
Next: ../validation-errors
Click to show internal directories.
Click to hide internal directories.