handle-errorf

command
v14.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL