fix(error): catch socket auth error as 4xx#4059
Conversation
PR SummaryLow Risk Overview Adds a warning log for these cases while keeping existing 500 logging/response for unexpected token generation failures. Reviewed by Cursor Bugbot for commit ff5c846. Bugbot is set up for automated code reviews on this repo. Configure here. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryThis PR fixes a bug where Confidence Score: 5/5This PR is safe to merge — it is a focused, single-file bug fix with no regressions risk. The change is minimal and narrowly scoped: a single catch-block addition that remaps a known better-auth UNAUTHORIZED error to 401. All logging standards are followed, no No files require special attention.
|
| Filename | Overview |
|---|---|
| apps/sim/app/api/auth/socket-token/route.ts | Adds a targeted catch for better-auth's UNAUTHORIZED APIError, returning 401 instead of 500; uses correct logger/import conventions with a minor type-assertion style issue. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[POST /api/auth/socket-token] --> B{Auth disabled?}
B -- Yes --> C[Return anonymous socket identifier]
B -- No --> D[Call auth.api.generateOneTimeToken]
D --> E{Success?}
E -- Yes, response exists --> F[Return 200 with socket identifier]
E -- No response value --> G[Return 401 Authentication required]
D --> H{Error thrown?}
H -- statusCode 401 or status UNAUTHORIZED --> I[logger.warn + Return 401]
H -- Other error --> J[logger.error + Return 500]
Reviews (1): Last reviewed commit: "fix(error): catch socket auth error as 4..." | Re-trigger Greptile
Summary
Better auth on invalid/expired tokens throws UNAUTHORIZED. We were throwing as 5xx, fixed to throw correctly as a 4xx.
Type of Change
Testing
Checklist
Screenshots/Videos