@@ -23,17 +23,26 @@ const headers = {
2323
2424async function pteroFetch ( path , options = { } ) {
2525 const url = `${ PTERO_URL } /api/application${ path } ` ;
26- const res = await fetchWithTimeout ( url , {
27- ...options ,
28- headers : { ...headers , ...options . headers } ,
29- } ) ;
30- if ( res . status === 204 ) return null ;
31- const data = await res . json ( ) ;
32- if ( ! res . ok ) {
33- const detail = data ?. errors ?. [ 0 ] ?. detail || JSON . stringify ( data ) ;
34- throw new Error ( detail ) ;
26+ const maxRetries = 3 ;
27+ for ( let attempt = 1 ; attempt <= maxRetries ; attempt ++ ) {
28+ const res = await fetchWithTimeout ( url , {
29+ ...options ,
30+ headers : { ...headers , ...options . headers } ,
31+ } ) ;
32+ if ( res . status === 204 ) return null ;
33+ if ( res . status === 429 && attempt < maxRetries ) {
34+ const wait = Math . min ( 1000 * Math . pow ( 2 , attempt - 1 ) , 8000 ) ;
35+ console . warn ( `pteroFetch rate limited (429), retry ${ attempt } /${ maxRetries } after ${ wait } ms` ) ;
36+ await new Promise ( r => setTimeout ( r , wait ) ) ;
37+ continue ;
38+ }
39+ const data = await res . json ( ) ;
40+ if ( ! res . ok ) {
41+ const detail = data ?. errors ?. [ 0 ] ?. detail || JSON . stringify ( data ) ;
42+ throw new Error ( detail ) ;
43+ }
44+ return data ;
3545 }
36- return data ;
3746}
3847
3948export async function createPteroUser ( { email, username, firstName, lastName, password } ) {
0 commit comments