fix(agent-bff): wrap action errors in the standard error envelope - #1799
Open
Tonours wants to merge 1 commit into
Open
fix(agent-bff): wrap action errors in the standard error envelope#1799Tonours wants to merge 1 commit into
Tonours wants to merge 1 commit into
Conversation
|
Coverage Impact This PR will not change total coverage. Modified Files with Diff Coverage (2)
🛟 Help
|
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

fixes PRD-867
Problem
Every BFF failure goes out in the shared envelope. Except one. A native action error
(
resultBuilder.error(...)) came out flat, no wrapper:{ "type": "error", "status": 400, "message": "SAR already filed", "html": "<strong>…</strong>" }Everything else:
{ "error": { "type": "unknown_field", "status": 422, "message": "..." } }PRD-641 says the Zendesk client branches on
error.type. That branch never fires here.response.errorisundefined, so the client skips it and reads a business failure as a success. Theagent's message and its
htmlare dropped. Nothing crashes, the result is just wrong.Found during the PRD-674 manual QA, against a real agent.
Root cause
action-routes-middleware.tsassignedctx.status/ctx.bodyby hand forActionFormValidationError. That bypassestoErrorBody, the function that owns the envelope shape.That is how the two shapes drifted apart.
Fix
Throw a
BffHttpErrorinstead of writing the body. The error middleware runs it throughtoErrorBody, so this response cannot drift again:{ "error": { "type": "action_error", "status": 400, "message": "...", "details": { "html": "..." } } }The agent's
htmlrides indetails, the envelope's only extension point.toErrorBodyalready omitsdetailswhen undefined, andActionFormValidationError.htmlis alreadyoptional. So "key absent, not
null" needed no extra code. The old?? nullwas what forced theexplicit
null.Scope
Unchanged: the four other action result shapes.
success,webhook,redirectstay flat onbody.type.unsupported_action_result(501) was already enveloped. A new test pins a success asflat, so nobody wraps the rest by accident.
Breaking change, taken on purpose.
type: "error"was one of five action result shapes and two testsasserted it. Uniformising costs that symmetry: a failure now reads
body.error.typewhile the otheroutcomes read
body.type. What it buys is one error path in the client instead of two. Free todaybecause no consumer exists. After PRD-678 writes the Zendesk client it breaks a shipped integration.
How to test
yarn workspace @forestadmin/agent-bff testOn an action whose
executereturnsresultBuilder.error(msg, { html }):{ type: "error", status: 400, message, html }{ error: { type: "action_error", status: 400, message, details: { html } } }Manually, through the PRD-674 QA suite (
qa-execute-e2e.shsection 8, updated to assert the envelopeand no top-level
type): an already-filed SAR returns the enveloped 400, and the same action on anunfiled SAR still returns 200. So the error branch is what gets exercised, not a permanently broken
action.
Validation
macroscope codereviewagainstorigin/main: completed, zero findings.Definition of Done
General
Security