Repository navigation
[i18n] Send message codes with API messages (issues#3157) - #80
Merged
Merged
Conversation
Responses keep their English `message` (or `error`) and now also carry a
stable `code` plus `params`, so the editor and the hax CLI can show the
message in the user's language.
- src/lib/haxcmsApiCodes.json: copy of the shared code list from
@haxtheweb/haxcms-elements/lib/haxcms-api-codes.json (same file in
haxcms-php). Each code has English text and patterns for the messages
this backend already sends; named groups become params.
- src/lib/apiMessageCodes.js: matches a message to its code and adds
code/params to the response body (top level, data, __failed). Codes a
handler sets itself are kept. Successful responses only get codes for
the few messages meant for success ("Site archived" and similar).
- app.js: middleware annotates every res.json; cli.js: the CLI bridge does
the same so in-process callers get identical bodies.
- OpenAPI specs document data.code and data.params.
- Tests: matching, envelope shapes, middleware, and a scan that fails when
a route sends a message literal with no code, so new messages get one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EN4mJgNh8uj2C44jDs4KAD
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of haxtheweb/issues#3157. Pairs with haxtheweb/webcomponents#883, which holds the source copy of the code list. Merge that first or alongside this. Nothing here depends on the editor: this only adds fields.
What it touches
message(orerror) and also getcode+params, e.g.{status:404, data:{message:'Item not found for idOrSlug "intro"', code:'ITEM_NOT_FOUND', params:{idOrSlug:'intro'}}}src/lib/haxcmsApiCodes.json: copy of@haxtheweb/haxcms-elements/lib/haxcms-api-codes.json(haxcms-php has the same file).src/lib/apiMessageCodes.js:code/paramsat the top level,data, or__failed.src/app.js: one middleware wrapsres.json, so no route handlers changed.src/cli.js: the CLI bridge annotates the same way, so in-process callers (the hax CLI) get identical bodies.site-spec,system-spec): documentdata.codeanddata.paramson the error envelope.Why recognise messages centrally instead of editing ~450 call sites
Coverage is complete today and the diff stays small. A route can still set
codeexplicitly when it wants to. The trade-off is that new English messages need a pattern. The new test catches that: it parsessrc/and fails on anymessage:/error:literal without a code.Tests
test/unit/api-message-codes.test.cjs: catalog validity, examples, envelope shapes, middleware, the literal scan, and a sync check against the copy bundled insrc/public/build(runs once a build with it lands).app-server-upload-lifecycleexpectations now include the code.npm testlocally: 2,666 pass, 0 fail. The pdf export tests needPUPPETEER_EXECUTABLE_PATH, same as before.Generated by Claude Code