Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(error): catch socket auth error as 4xx
  • Loading branch information
TheodoreSpeaks committed Apr 8, 2026
commit ed9e39d0bd898d3b8924d97fa01d01692fa09fda
8 changes: 8 additions & 0 deletions apps/sim/app/api/auth/socket-token/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ export async function POST() {

return NextResponse.json({ token: response.token })
} catch (error) {
// better-auth's sessionMiddleware throws APIError("UNAUTHORIZED") with no message
// when the session is missing/expired — surface this as a 401, not a 500.
const apiError = error as { statusCode?: number; status?: string }
if (apiError.statusCode === 401 || apiError.status === 'UNAUTHORIZED') {
Comment thread
TheodoreSpeaks marked this conversation as resolved.
Outdated
logger.warn('Socket token request with invalid/expired session')
return NextResponse.json({ error: 'Authentication required' }, { status: 401 })
}

logger.error('Failed to generate socket token', {
error: error instanceof Error ? error.message : String(error),
stack: error instanceof Error ? error.stack : undefined,
Expand Down
Loading