@@ -91,10 +91,10 @@ async function fetchToken() {
9191 "Content-Type" : "application/json" ,
9292 } ,
9393 } ) ;
94+ const data = await response . json ( ) ;
9495 if ( ! response . ok ) {
95- throw new Error ( `Error ${ response . status } : ${ response . statusText } ` ) ;
96+ errorMessage ( data . response . message ) ;
9697 }
97- const data = await response . json ( ) ;
9898 localStorage . setItem ( "access_token" , data . access_token ) ;
9999 accessToken = localStorage . getItem ( "access_token" ) ;
100100 } catch ( error ) {
@@ -140,6 +140,7 @@ async function userInfo() {
140140 userType1 = "teacher" ;
141141 } else if ( ! data . response . data [ 0 ] ) {
142142 console . error ( data ) ;
143+ errorMessage ( data . response . message ) ;
143144 } else {
144145 schoolInSchoolYears ( data . response . data [ 0 ] . schoolInSchoolYears ) ;
145146 }
@@ -366,7 +367,10 @@ function show(id, title, hideBack) {
366367 }
367368 } ) ;
368369}
369-
370+ function errorMessage ( e ) {
371+ document . querySelector ( "#error p" ) . innerText = e ;
372+ document . getElementById ( "error" ) . showModal ( ) ;
373+ }
370374function renderAnnouncements ( ) {
371375 const content = document . getElementById ( "allAnnouncements" ) ;
372376 content . innerHTML = "" ;
@@ -501,6 +505,9 @@ async function fetchSchedule(year, week, isFirstLoad) {
501505 }
502506 ) ;
503507 const data = await response . json ( ) ;
508+ if ( ! response . ok ) {
509+ errorMessage ( data . response . message ) ;
510+ }
504511 const appointments = data . response . data [ 0 ] . appointments ;
505512 const isHoliday = ! appointments [ 0 ] ;
506513 const schedule = document . getElementById ( "schedule" ) ;
0 commit comments