fix(api): classify access-denied and sandbox user-code errors with correct HTTP status#4740
Conversation
…rrect HTTP status
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview Workspace access now throws
Reviewed by Cursor Bugbot for commit 2e2d10b. Configure here. |
Greptile SummaryThis PR fixes HTTP status code classification for two classes of previously-misclassified 500 errors: workspace access-denied checks (now 403) and E2B sandbox user-code failures (now 422). It introduces a typed
Confidence Score: 5/5Safe to merge — changes are targeted status-code reclassifications with no business logic alterations. All seven routes that call assertActiveWorkspaceAccess (directly or through resolveOrCreateChat / generateWorkspaceContext) were audited and updated. The withRouteHandler fallback provides a safety net for any future typed error. The 422 change for E2B errors mirrors the pre-existing isolated-VM behavior, making the execution paths consistent. No auth logic, data mutations, or core execution paths were modified. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Route Handler] -->|try| B[assertActiveWorkspaceAccess]
B -->|access OK| C[Continue handler logic]
B -->|access denied| D[throw WorkspaceAccessDeniedError\nstatusCode = 403]
D -->|explicit inner catch| E{isWorkspaceAccessDeniedError?}
E -->|yes| F[createForbiddenResponse\n403 — 'Workspace access denied']
E -->|no / not present| G[withRouteHandler catch]
G -->|readTypedErrorStatus| H{statusCode 400–599?}
H -->|yes| I[NextResponse 403\nerror: message includes workspaceId]
H -->|no| J[NextResponse 500\nerror: 'Internal server error']
K[E2B sandbox execute] -->|shellError / e2bError| L[functionJsonResponse\n422 — user code error]
M[isolated-vm execute] -->|vm error| N[functionJsonResponse\n422 — already correct]
Reviews (3): Last reviewed commit: "refactor(api): match NestJS/Spring conve..." | Re-trigger Greptile |
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit d5683f5. Configure here.
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 2e2d10b. Configure here.
Summary
WorkspaceAccessDeniedError(statusCode 403) thrown byassertActiveWorkspaceAccess; route catch blocks map it to 403 instead of swallowing as 500. Updates: mothership/chats GET+POST, mothership/chats/[chatId]/fork, mothership/execute, copilot/chats POST, copilot/chat queries, tools/file/manage, copilot chat post (unified handler)withRouteHandlernow reads a numericstatusCodeoff unhandled Errors and maps to that status; falls back to 500 otherwise. Covers future typed errors automatically/api/function/executereturns 422 (instead of 500) for E2B shell, JS, and Python user-code errors — mirrors the existing isolated-vm pathcreateForbiddenResponsehelper inlib/copilot/request/http.tsType of Change
Testing
bun run check:api-validationpassestsc --noEmitfor apps/sim cleanChecklist