File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
apps/sim/app/api/auth/socket-token Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,18 @@ export async function POST() {
2323
2424 return NextResponse . json ( { token : response . token } )
2525 } catch ( error ) {
26+ // better-auth's sessionMiddleware throws APIError("UNAUTHORIZED") with no message
27+ // when the session is missing/expired — surface this as a 401, not a 500.
28+ if (
29+ error instanceof Error &&
30+ ( 'statusCode' in error || 'status' in error ) &&
31+ ( ( error as Record < string , unknown > ) . statusCode === 401 ||
32+ ( error as Record < string , unknown > ) . status === 'UNAUTHORIZED' )
33+ ) {
34+ logger . warn ( 'Socket token request with invalid/expired session' )
35+ return NextResponse . json ( { error : 'Authentication required' } , { status : 401 } )
36+ }
37+
2638 logger . error ( 'Failed to generate socket token' , {
2739 error : error instanceof Error ? error . message : String ( error ) ,
2840 stack : error instanceof Error ? error . stack : undefined ,
You can’t perform that action at this time.
0 commit comments