@@ -110,8 +110,19 @@ const Landing = () => {
110110 } )
111111 . catch ( ( err ) => {
112112 let error = err . response ? err . response . data : err ;
113+ // get error status
114+ let status = err . response . status ;
115+ console . log ( "status" , status ) ;
116+ if ( status === 429 ) {
117+ console . log ( "too many requests" , status ) ;
118+
119+ showErrorToast (
120+ `Quota of 100 requests exceeded for the Day! Please read the blog on freeCodeCamp to learn how to setup your own RAPID API Judge0!` ,
121+ 10000
122+ ) ;
123+ }
113124 setProcessing ( false ) ;
114- console . log ( error ) ;
125+ console . log ( "catch block..." , error ) ;
115126 } ) ;
116127 } ;
117128
@@ -130,17 +141,18 @@ const Landing = () => {
130141 let statusId = response . data . status ?. id ;
131142
132143 // Processed - we have a result
133- if ( statusId !== 1 && statusId !== 2 ) {
134- setProcessing ( false ) ;
135- setOutputDetails ( response . data ) ;
136- showSuccessToast ( ) ;
137- console . log ( "response.data" , response . data ) ;
138- return ;
139- } else {
144+ if ( statusId === 1 || statusId === 2 ) {
140145 // still processing
141146 setTimeout ( ( ) => {
142147 checkStatus ( token ) ;
143148 } , 2000 ) ;
149+ return ;
150+ } else {
151+ setProcessing ( false ) ;
152+ setOutputDetails ( response . data ) ;
153+ showSuccessToast ( `Compiled Successfully!` ) ;
154+ console . log ( "response.data" , response . data ) ;
155+ return ;
144156 }
145157 } catch ( err ) {
146158 console . log ( "err" , err ) ;
@@ -176,10 +188,10 @@ const Landing = () => {
176188 progress : undefined ,
177189 } ) ;
178190 } ;
179- const showErrorToast = ( msg ) => {
191+ const showErrorToast = ( msg , timer ) => {
180192 toast . error ( msg || `Something went wrong! Please try again.` , {
181193 position : "top-right" ,
182- autoClose : 1000 ,
194+ autoClose : timer ? timer : 1000 ,
183195 hideProgressBar : false ,
184196 closeOnClick : true ,
185197 pauseOnHover : true ,
0 commit comments