feat: add WithPlatformCode for domain-level error identity (v0.10.0) #2
Reference in New Issue
Block a user
Delete Branch "feature/platform-code"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds
WithPlatformCode/PlatformCode()to*Err— an optional domain-level error identifier that is fully decoupled from the transport-levelCode.Why two codes?
CodeNOT_FOUND→ 404).PlatformCodeEMPLOYEE_NOT_FOUND). Open-ended, consumer-defined.A
NOT_FOUNDtransport code cannot tell a frontend whether an employee, a role, or a branch was missing — it falls back to a generic message.PlatformCodegives the frontend the exact signal it needs to render a specific translated message, without the backend carrying any locale-specific copy.Platform codes are optional. Errors without a user-actionable meaning (500 internals, infrastructure failures, auth rejections) carry none.
Changes
(*Err).WithPlatformCode(code string) *Err— chainable builder(*Err).PlatformCode() string— getter (empty string if not set)MarshalJSONincludes"platformCode"when set, omits otherwise (omitempty)Backwards compatibility
Fully additive — no existing signatures, behaviour, or JSON output changed for errors that don't use
WithPlatformCode.Test plan
go test ./...passesplatformCodepresent in JSON when setplatformCodeabsent from JSON when not setWithContextandWithErrorworks correctlyCode()unaffected byWithPlatformCode🤖 Generated with Claude Code
LGTM