fix(engine): always answer JSON from the generic action endpoint#712
fix(engine): always answer JSON from the generic action endpoint#712romain-pm wants to merge 1 commit into
Conversation
📝 Documentation GuidelinesThank you for contributing to our documentation! To ensure your contributions meet our standards, please review these resources:
This comment is posted automatically when changes are detected in the |
|
Integration Tests are red here, but they are red on the base branch too — this PR does not cause it. Comparing this PR's run (job 89582047805) with #687's own latest run on Every spec reports The behaviour this PR changes was verified manually against a Jahia 8.2 instance instead — the request matrix in the description — and the Cypress spec was extended accordingly, so it should go green once the base branch's suite does. |
|
Root cause found and fixed — the red suite is a packaging regression on this branch, not an environment problem. (Supersedes my earlier comment, which only established that the failure predates this PR.) What breaks
A package-level diff of the two builds isolates it exactly: Why the whole suite diesFrom the run's The suite's first spec, The fixOne entry: Verified on Jahia 8.2
This also unblocks #687 itself; happy to move the commit into a standalone PR against |
Suite status: 41/41 specs, 154 → 155 tests (pending the run in flight)
Everything after the first line is repair of specs that have never passed on this branch — all three are new here — so this PR now carries branch repairs beyond its own subject. Happy to split them into a separate PR against One finding that deserves your call
The content locale decides, the UI locale is ignored. On the snapshot CI runs, the same request answers So either the platform changed which locale it passes to choicelist initializers between 8.2.1.0 and 8-SNAPSHOT, or the newer one resolves it from somewhere else entirely (session, default language). The module is not at fault either way — it localizes with whatever it is handed — so the test now asks for French on both locales and keeps asserting the French label. The comment in the spec records the divergence. Worth chasing on the Jahia side before this branch ships, since the documented promise ("initializers receive the content locale") is what the feature's users will code against. |
`Render#doAction` only serializes an action's JSON when the caller asked for it — a `returnContentType=json` parameter, or an `accept` header containing `application/json` — and otherwise falls through to its redirect branch, which for a JSON-only action means an empty 200 with nothing logged. The generated client stubs always send the header, so this was invisible from the browser but hit every hand-rolled caller: curl, tests, server-to-server integrations, all silently getting a blank body, including on error paths. The endpoint now writes its envelope to the response itself and returns null, which tells the render servlet the response is complete. Freed from the 2xx-only constraint of that code path, failures also get meaningful statuses: 400 when an action's schema rejects the input (the envelope keeps its `issues`), 404 for an unknown action name, 500 when the function throws or the runtime cannot complete the call. Malformed calls are logged, which they were not before. The generated stub now reads the envelope before looking at the status, so a validation failure still rejects with the server's message and issues rather than a bare "failed with HTTP 400". Verified on a Jahia 8.2 instance, with and without the accept header, across success, schema rejection, thrown error, unknown action and missing-header cases; and from a browser island through the generated stubs. Closes #707
ac36072 to
4fd7d96
Compare
|
Rescoped. The four branch-repair commits moved to #713 (against Its base is now The earlier comments about the packaging regression and the locale routing describe #713's territory — kept here for continuity, but that is where they belong now. |
Closes #707 — part of EPIC #698 (developer experience).
The bug
The action runs; only its response disappears.
Render#doAction(jahia-impl 8.2.3.0, around line 1199) writes an action's JSON only when the caller asked for it:With no
acceptheader the endpoint's envelope falls into the redirect branch with a null URL: empty 200. The generated stubs always send the header, so this never showed in a browser — but every hand-rolled caller (curl, tests, server-to-server) got silence, on success and on every error path.Change
The endpoint writes its envelope to the response itself and returns
null, which isRender#doAction's own signal that the response is complete (if (result != null)). No core change.Freed from that path's 2xx-only constraint, failures now carry a status:
200400issues) — or a missingX-JS-Actionheader / action name404500Validation failures and thrown errors are distinguished by the presence of
issues: a schema rejection is the caller's fault, a barethrowis the server's — the same split Astro Actions makes. Malformed calls are now logged; they were invisible server-side too.The generated client stub reads the envelope before the status, so a 400 still rejects with the server's message and issues rather than a bare "failed with HTTP 400".
Verification
Live on Jahia 8.2, against the test module's action fixtures, without an
acceptheader unless stated:add(1,2)200 {"data":"[3]"}add(1,2)withaccept: application/jsonsafeDouble(21)200 {"data":"[42]"}safeDouble(-5)400 {"error":"n must be a positive number","issues":[…]}failOnPurpose()500 {"error":"Intentional failure"}404 {"error":"Unknown action: …"}X-JS-Action400 {"error":"Missing X-JS-Action header"}And from a browser island through the generated stubs: success returns 42, a validation failure still surfaces
n must be a positive number(proving the stub reads the body before the status), a thrown error still surfacesIntentional failure.The Cypress action spec gains a case for the missing-
acceptpath and now asserts the status of every outcome.docs/2-guides/7-actionsdocuments calling actions without the stub, with the status table.