Overview
See #3454173-45: Media Library integration (includes introducing a new main content renderer/`_wrapper_format`) for how #3450308: Create an Open API spec for the current mock HTTP responses actually caused the DX to regress rather than improve in some scenarios.
(In this case: an empty Ajax response was sent, with no visible error — the error itself was logged. This is very non-obvious 😬)
Proposed resolution
Ensure that
throw new ValidationFailed($message, $e->getCode(), $e);
… actually results in an appropriate error response being generated.
User interface changes
None … except in case of fatal errors, then you get an actually-useful-to-report error message:

| Comment | File | Size | Author |
|---|---|---|---|
| #14 | Screenshot from 2024-09-20 15-03-44.png | 21.47 KB | longwave |
| #11 | Screenshot from 2024-09-20 14-27-44.png | 132.92 KB | longwave |
| #2 | Screenshot 2024-08-30 at 10.47.29 AM.png | 549.23 KB | wim leers |
Issue fork experience_builder-3470995
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
wim leersIf such errors are always JSON responses, then we can update the work @balintbrews introduced in #3461431: Improve client side error handling to surface a friendlier error than this:
Comment #3
wim leersAha, for #2 we already have #3470321: Surface verbose OpenAPI errors in the UI — for better bug reports and faster DX! 👍
But without a structured error response from the server for the client to consume, fixing #2 is impossible.
IOW: this is a blocker for #3470321: Surface verbose OpenAPI errors in the UI — for better bug reports and faster DX.
Comment #6
wim leersTransfering relevant info + credit from #3470321: Surface verbose OpenAPI errors in the UI — for better bug reports and faster DX:
— @traviscarden, #3470321-4: Surface verbose OpenAPI errors in the UI — for better bug reports and faster DX
— @effulgentsia, #3470321-5: Surface verbose OpenAPI errors in the UI — for better bug reports and faster DX.
Comment #9
longwaveComment #10
longwaveThe implementation here:
_formatrequirementexperience_builder.*This is enough to get started on displaying nicer errors on the client. I am not sure a stack trace would be useful to the client but it might be useful to send in the JSON data anyway, for debugging via the network inspector?
Comment #11
longwaveA screenshot of this in action, exploiting the crash in #3469855: Emptying a required value through the UI crashes the app (empty <input>, selecting "None" option in <select> …) before that fix is merged:
Comment #12
longwaveSimplified this further, we have precedent in XbRouteOptionsEventSubscriber for API routes already so I used that instead - no need to force
_format: json(although perhaps we still should for correctness?)Comment #13
longwaveIt turns out that EntityFormControllerTest already tests an error that should be returned in JSON format, so I reworked the test case there to expect JSON instead - that should be enough coverage to start with?
I also ported the stack trace functionality from JSON:API module with the same conditions, and the test covers that too.
Comment #14
longwaveWith a one line change I've exposed the message in the UI if the preview endpoint fails:
Comment #15
traviscarden commentedI can RTBC this as soon as the (trivial) requested change is made.
Comment #16
longwaveComment #17
longwaveReverted the UI change as it's not TypeScript safe, and should be done in #3470321: Surface verbose OpenAPI errors in the UI — for better bug reports and faster DX
Comment #18
traviscarden commentedNice. This should immediately improve the experience for everyone.
I don't seem to have the ability to actually merge the MR, so I'll mark this RTBC until I can get it.
Comment #19
wim leersAdding @longwave's excellent screenshot from #14 to the issue summary.
Comment #20
traviscarden commentedI've been trying to get access to merge this MR all day, and despite apparently having all the necessary permissions, I still cannot. So if someone who can merge it kindly would, that would be great. You have my approval to do so.
Comment #23
hooroomooMerging on behalf of @traviscarden.