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

- 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>

Reviewed-on: #1
Reviewed-by: Rene Nochebuena <rene@noreply.nochebuena.dev>
Co-authored-by: Claude Code <claude@nochebuena.dev>
Co-committed-by: Claude Code <claude@nochebuena.dev>
This commit was merged in pull request #1.
This commit is contained in:
2026-03-25 16:57:49 -06:00
committed by NOCHEBUENADEV
parent 285293a75b
commit 8d34a0c715
5 changed files with 47 additions and 6 deletions

View File

@@ -240,6 +240,28 @@ func TestError_NilError(t *testing.T) {
}
}
func TestError_PlatformCode_IncludedWhenSet(t *testing.T) {
rec := httptest.NewRecorder()
Error(rec, xerrors.New(xerrors.ErrNotFound, "employee not found").
WithPlatformCode("EMPLOYEE_NOT_FOUND"))
if rec.Code != http.StatusNotFound {
t.Errorf("want 404, got %d", rec.Code)
}
m := decodeMap(t, rec)
if m["platformCode"] != "EMPLOYEE_NOT_FOUND" {
t.Errorf("platformCode: want EMPLOYEE_NOT_FOUND, got %v", m["platformCode"])
}
}
func TestError_PlatformCode_OmittedWhenNotSet(t *testing.T) {
rec := httptest.NewRecorder()
Error(rec, xerrors.New(xerrors.ErrInternal, "unexpected error"))
m := decodeMap(t, rec)
if _, ok := m["platformCode"]; ok {
t.Errorf("platformCode should be absent for errors without a platform code, got %v", m["platformCode"])
}
}
func TestErrorCodeToStatus_AllCodes(t *testing.T) {
cases := []struct {
code xerrors.Code