@@ -221,42 +221,19 @@ export async function authedFetch(
221221 const url = new URL ( endpoint , deployUrl ) ;
222222
223223 let fallbackBody : ReadableStream | undefined ;
224- try {
225- if ( init . body instanceof ReadableStream ) {
226- const [ a , b ] = init . body . tee ( ) ;
227- init . body = a ;
228- fallbackBody = b ;
229- }
230-
231- const res = await fetch ( url , {
232- ...init ,
233- headers,
234- } ) ;
235-
236- if ( res . status === 401 ) {
237- token_storage . remove ( ) ;
238- auth = await getAuth ( deployUrl ) ;
224+ if ( init . body instanceof ReadableStream ) {
225+ const [ a , b ] = init . body . tee ( ) ;
226+ init . body = a ;
227+ fallbackBody = b ;
228+ }
239229
240- const headers = new Headers ( init . headers ) ;
241- headers . set (
242- "cookie" ,
243- `token=${ auth } ; deno_auth_ghid=force` ,
244- ) ;
245- const res = await fetch ( url , {
246- ...init ,
247- headers,
248- } ) ;
230+ const res = await fetch ( url , {
231+ ...init ,
232+ headers,
233+ } ) ;
249234
250- if ( res . status === 401 ) {
251- const err = await res . json ( ) ;
252- error ( `unexpected authentication failure\n${ err . message } ` ) ;
253- } else {
254- return res ;
255- }
256- } else {
257- return res ;
258- }
259- } catch {
235+ if ( res . status === 401 ) {
236+ console . log ( await res . text ( ) ) ;
260237 token_storage . remove ( ) ;
261238 auth = await getAuth ( deployUrl ) ;
262239
@@ -265,17 +242,19 @@ export async function authedFetch(
265242 "cookie" ,
266243 `token=${ auth } ; deno_auth_ghid=force` ,
267244 ) ;
268- const res = await fetch ( url , {
245+ const retryRes = await fetch ( url , {
269246 ...init ,
270247 headers,
271248 body : init . body instanceof ReadableStream ? fallbackBody : init . body ,
272249 } ) ;
273250
274- if ( res . status === 401 ) {
275- const err = await res . json ( ) ;
251+ if ( retryRes . status === 401 ) {
252+ const err = await retryRes . json ( ) ;
276253 error ( `unexpected authentication failure\n${ err . message } ` ) ;
277254 } else {
278- return res ;
255+ return retryRes ;
279256 }
257+ } else {
258+ return res ;
280259 }
281260}
0 commit comments