@@ -42,12 +42,20 @@ async function joinRoomApi(roomId, token) {
4242 credentials : 'include' ,
4343 } ) ;
4444
45- if ( ! res . ok ) {
46- const text = await res . text ( ) . catch ( ( ) => '' ) ;
47- if ( res . status === 409 ) return { status : 'already_joined' } ;
48- throw new Error ( text || `HTTP ${ res . status } ` ) ;
45+ if ( res . ok ) {
46+ const data = await res . json ( ) . catch ( ( ) => null ) ;
47+ if ( data && typeof data === 'object' ) {
48+ return data . status ? data : { status : 'success' , ...data } ;
49+ }
50+ return { status : 'success' } ;
51+ }
52+
53+ const text = await res . text ( ) . catch ( ( ) => '' ) ;
54+ if ( res . status === 409 ) return { status : 'already_joined' , message : text } ;
55+ if ( res . status === 404 || res . status === 403 ) {
56+ return { status : 'not_found' , message : text || '존재하지 않는 방송 코드입니다.' } ;
4957 }
50- return await res . json ( ) . catch ( ( ) => ( { status : 'success' } ) ) ;
58+ throw new Error ( text || `HTTP ${ res . status } ` ) ;
5159}
5260
5361
@@ -556,8 +564,13 @@ export default function CodecastLive({ isDark }) {
556564 try {
557565 if ( token && room . id ) {
558566 console . log ( '[API] Joining room via REST API:' , room . id ) ;
559- await joinRoomApi ( room . id , token ) ;
560- console . log ( '[API] Room joined successfully or already registered.' ) ;
567+ const joinResult = await joinRoomApi ( room . id , token ) ;
568+ if ( joinResult ?. status === 'not_found' ) {
569+ alert ( joinResult . message || '존재하지 않는 방송 코드입니다.' ) ;
570+ navigate ( '/broadcast' , { replace : true } ) ;
571+ return ;
572+ }
573+ console . log ( '[API] Room joined successfully or already registered.' , joinResult ) ;
561574 }
562575
563576 console . log ( '[WS] effect start' , { roomId : room . id , hasToken : ! ! token } ) ;
@@ -608,7 +621,7 @@ export default function CodecastLive({ isDark }) {
608621 return ( ) => {
609622 unsubs . forEach ( ( u ) => u ?. ( ) ) ;
610623 } ;
611- } , [ room . id , token , connect , subscribeSystem ] ) ;
624+ } , [ room . id , token , connect , subscribeSystem , navigate ] ) ;
612625
613626 useEffect ( ( ) => {
614627 if ( ! room . id || ! sessionId ) return ;
0 commit comments