feat: include platformCode in error responses (v0.10.0) #1

Merged
Rene Nochebuena merged 1 commits from feature/platform-code into main 2026-03-25 16:57:50 -06:00
Member

Summary

  • Error(w, err) now extracts PlatformCode() from *xerrors.Err and includes "platformCode" in the JSON error body when set; omitted when not set (backwards-compatible)
  • errorBody updated to accept platformCode as an explicit parameter
  • Upgraded code.nochebuena.dev/go/xerrors dependency to v0.10.0
  • Two new tests: TestError_PlatformCode_IncludedWhenSet, TestError_PlatformCode_OmittedWhenNotSet

Error response shape

With platform code:

{
  "code": "NOT_FOUND",
  "platformCode": "EMPLOYEE_NOT_FOUND",
  "message": "employee not found"
}

Without platform code (unchanged from v0.9.0):

{
  "code": "NOT_FOUND",
  "message": "employee not found"
}

Motivation

Frontend teams need a stable, transport-agnostic identifier for domain errors to drive i18n message lookup. Code is transport-bounded (ErrNotFound → 404); platformCode is open-ended and domain-specific. The transport layer passes it through transparently — no mapping logic added here.

Test plan

  • go test ./... passes
  • TestError_PlatformCode_IncludedWhenSet — 404 response contains platformCode: "EMPLOYEE_NOT_FOUND"
  • TestError_PlatformCode_OmittedWhenNotSet — response body has no platformCode key
  • All existing tests pass unchanged

🤖 Generated with Claude Code

## Summary - `Error(w, err)` now extracts `PlatformCode()` from `*xerrors.Err` and includes `"platformCode"` in the JSON error body when set; omitted when not set (backwards-compatible) - `errorBody` updated to accept `platformCode` as an explicit parameter - Upgraded `code.nochebuena.dev/go/xerrors` dependency to `v0.10.0` - Two new tests: `TestError_PlatformCode_IncludedWhenSet`, `TestError_PlatformCode_OmittedWhenNotSet` ## Error response shape With platform code: ```json { "code": "NOT_FOUND", "platformCode": "EMPLOYEE_NOT_FOUND", "message": "employee not found" } ``` Without platform code (unchanged from v0.9.0): ```json { "code": "NOT_FOUND", "message": "employee not found" } ``` ## Motivation Frontend teams need a stable, transport-agnostic identifier for domain errors to drive i18n message lookup. `Code` is transport-bounded (`ErrNotFound` → 404); `platformCode` is open-ended and domain-specific. The transport layer passes it through transparently — no mapping logic added here. ## Test plan - [x] `go test ./...` passes - [x] `TestError_PlatformCode_IncludedWhenSet` — 404 response contains `platformCode: "EMPLOYEE_NOT_FOUND"` - [x] `TestError_PlatformCode_OmittedWhenNotSet` — response body has no `platformCode` key - [x] All existing tests pass unchanged 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude added 1 commit 2026-03-25 16:57:08 -06:00
- Error(w, err) now extracts PlatformCode() from *xerrors.Err and
  includes "platformCode" in the JSON body when set; omitted otherwise
- errorBody updated to accept platformCode as an explicit parameter
- Upgraded code.nochebuena.dev/go/xerrors dependency to v0.10.0
- Added two new tests: platformCode included when set, omitted when absent

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Rene Nochebuena approved these changes 2026-03-25 16:57:45 -06:00
Rene Nochebuena left a comment
Owner

LGTM

LGTM
Rene Nochebuena merged commit 8d34a0c715 into main 2026-03-25 16:57:50 -06:00
Rene Nochebuena deleted branch feature/platform-code 2026-03-25 16:57:50 -06:00
Sign in to join this conversation.