fix(httputil): rename error body field platformCode → platform_code

errorBody() map key corrected from "platformCode" to "platform_code" to
match the OpenAPI spec snake_case convention. All HTTP error responses
produced by Error(w, err) now emit "platform_code" in the JSON body.
PR.md added to .gitignore.
Depends on xerrors v1.0.2 (go.mod bumped in follow-up commit after xerrors tag).
This commit is contained in:
2026-05-21 19:32:35 -06:00
parent e8adc266a6
commit ccfa3d1527
6 changed files with 20 additions and 6 deletions

1
.gitignore vendored
View File

@@ -36,3 +36,4 @@ Thumbs.db
# VCS files # VCS files
COMMIT.md COMMIT.md
RELEASE.md RELEASE.md
PR.md

View File

@@ -5,6 +5,17 @@ All notable changes to this module will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.1] - 2026-05-22
### Fixed
- `errorBody` JSON key corrected from `"platformCode"` to `"platform_code"` to
match the OpenAPI spec snake_case convention. All HTTP error responses now
emit `"platform_code"` in the JSON body.
- Dependency `xerrors` bumped to v1.0.2.
[1.0.1]: https://code.nochebuena.dev/go/httputil/compare/v1.0.0...v1.0.1
## [1.0.0] - 2026-05-12 ## [1.0.0] - 2026-05-12
### Changed ### Changed

2
go.mod
View File

@@ -4,7 +4,7 @@ go 1.26
require ( require (
code.nochebuena.dev/go/valid v1.0.1 code.nochebuena.dev/go/valid v1.0.1
code.nochebuena.dev/go/xerrors v1.0.1 code.nochebuena.dev/go/xerrors v1.0.2
) )
require ( require (

2
go.sum
View File

@@ -2,6 +2,8 @@ code.nochebuena.dev/go/valid v1.0.1 h1:8O7uW8ufPk8lZ2EvKmTJpIrp9WsNjRg/KqMTxeTAT
code.nochebuena.dev/go/valid v1.0.1/go.mod h1:tSZiKc/108a1hGUnKe/dCg+TfM9HPcrdhZyW4VgCLjU= code.nochebuena.dev/go/valid v1.0.1/go.mod h1:tSZiKc/108a1hGUnKe/dCg+TfM9HPcrdhZyW4VgCLjU=
code.nochebuena.dev/go/xerrors v1.0.1 h1:fgXoabY/ZwxAzaM1sKFf3sbL7ZHWyDxItB/rdbnl0mo= code.nochebuena.dev/go/xerrors v1.0.1 h1:fgXoabY/ZwxAzaM1sKFf3sbL7ZHWyDxItB/rdbnl0mo=
code.nochebuena.dev/go/xerrors v1.0.1/go.mod h1:03MMVfrhaf4XmTMgMrEUFCmuZPGHUCKDitiQvwCuwvY= code.nochebuena.dev/go/xerrors v1.0.1/go.mod h1:03MMVfrhaf4XmTMgMrEUFCmuZPGHUCKDitiQvwCuwvY=
code.nochebuena.dev/go/xerrors v1.0.2 h1:PHkn9RXJdvz5fm3n1TCLo2qCzBqBfnQj5/4oF0nEWyk=
code.nochebuena.dev/go/xerrors v1.0.2/go.mod h1:03MMVfrhaf4XmTMgMrEUFCmuZPGHUCKDitiQvwCuwvY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw= github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=

View File

@@ -248,8 +248,8 @@ func TestError_PlatformCode_IncludedWhenSet(t *testing.T) {
t.Errorf("want 404, got %d", rec.Code) t.Errorf("want 404, got %d", rec.Code)
} }
m := decodeMap(t, rec) m := decodeMap(t, rec)
if m["platformCode"] != "EMPLOYEE_NOT_FOUND" { if m["platform_code"] != "EMPLOYEE_NOT_FOUND" {
t.Errorf("platformCode: want EMPLOYEE_NOT_FOUND, got %v", m["platformCode"]) t.Errorf("platform_code: want EMPLOYEE_NOT_FOUND, got %v", m["platform_code"])
} }
} }
@@ -257,8 +257,8 @@ func TestError_PlatformCode_OmittedWhenNotSet(t *testing.T) {
rec := httptest.NewRecorder() rec := httptest.NewRecorder()
Error(rec, xerrors.New(xerrors.ErrInternal, "unexpected error")) Error(rec, xerrors.New(xerrors.ErrInternal, "unexpected error"))
m := decodeMap(t, rec) m := decodeMap(t, rec)
if _, ok := m["platformCode"]; ok { if _, ok := m["platform_code"]; ok {
t.Errorf("platformCode should be absent for errors without a platform code, got %v", m["platformCode"]) t.Errorf("platform_code should be absent for errors without a platform code, got %v", m["platform_code"])
} }
} }

View File

@@ -45,7 +45,7 @@ func errorBody(code, platformCode, message string, fields map[string]any) map[st
"message": message, "message": message,
} }
if platformCode != "" { if platformCode != "" {
m["platformCode"] = platformCode m["platform_code"] = platformCode
} }
for k, v := range fields { for k, v := range fields {
m[k] = v m[k] = v