Map domain failures deliberately
Return an*erreur.Error through response.Error:
Unauthenticated, Forbidden, InvalidParam, NotFound, Conflict, Transient, or another explicit category. Use Unexpected only when the service cannot classify the failure safely.
Treat codes as the compatibility surface
The standard error object can include:
Keep
code stable. Human-readable text can improve without forcing client releases.
Let the runtime own boundary failures
You do not need to recreate errors for malformed JSON, invalid parameters, unsupported methods or media types, request limits, missing authorization, unavailable callers, idempotency conflicts, or timeouts. The endpoint runtime rejects those conditions before or around the handler and renders the standard envelope.DefineJSONEndpoint also converts param.Error values automatically. Application handlers should only map failures from domain work they actually perform.
Preserve causes internally
Keep the original Go error in logs, traces, or an internal wrapper. Do not copy database messages, provider payloads, stack traces, or arbitrary error strings into publicmessage or detail fields.