@@ -107,7 +107,7 @@ export class GithubUrlReader implements UrlReader {
107
107
108
108
let response : Response ;
109
109
try {
110
- response = await fetch ( ghUrl , {
110
+ response = await this . fetchResponse ( ghUrl , {
111
111
headers : {
112
112
...credentials ?. headers ,
113
113
...( options ?. etag && { 'If-None-Match' : options . etag } ) ,
@@ -125,38 +125,13 @@ export class GithubUrlReader implements UrlReader {
125
125
signal : options ?. signal as any ,
126
126
} ) ;
127
127
} catch ( e ) {
128
- throw new Error ( `Unable to read ${ url } , ${ e } ` ) ;
128
+ throw e ;
129
129
}
130
130
131
- if ( response . status === 304 ) {
132
- throw new NotModifiedError ( ) ;
133
- }
134
-
135
- if ( response . ok ) {
136
- return ReadUrlResponseFactory . fromNodeJSReadable ( response . body , {
137
- etag : response . headers . get ( 'ETag' ) ?? undefined ,
138
- lastModifiedAt : parseLastModified (
139
- response . headers . get ( 'Last-Modified' ) ,
140
- ) ,
141
- } ) ;
142
- }
143
-
144
- let message = `${ url } could not be read as ${ ghUrl } , ${ response . status } ${ response . statusText } ` ;
145
- if ( response . status === 404 ) {
146
- throw new NotFoundError ( message ) ;
147
- }
148
-
149
- // GitHub returns a 403 response with a couple of headers indicating rate
150
- // limit status. See more in the GitHub docs:
151
- // https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting
152
- if (
153
- response . status === 403 &&
154
- response . headers . get ( 'X-RateLimit-Remaining' ) === '0'
155
- ) {
156
- message += ' (rate limit exceeded)' ;
157
- }
158
-
159
- throw new Error ( message ) ;
131
+ return ReadUrlResponseFactory . fromNodeJSReadable ( response . body , {
132
+ etag : response . headers . get ( 'ETag' ) ?? undefined ,
133
+ lastModifiedAt : parseLastModified ( response . headers . get ( 'Last-Modified' ) ) ,
134
+ } ) ;
160
135
}
161
136
162
137
async readTree (
@@ -350,10 +325,26 @@ export class GithubUrlReader implements UrlReader {
350
325
const response = await fetch ( urlAsString , init ) ;
351
326
352
327
if ( ! response . ok ) {
353
- const message = `Request failed for ${ urlAsString } , ${ response . status } ${ response . statusText } ` ;
328
+ let message = `Request failed for ${ urlAsString } , ${ response . status } ${ response . statusText } ` ;
329
+
330
+ if ( response . status === 304 ) {
331
+ throw new NotModifiedError ( ) ;
332
+ }
333
+
354
334
if ( response . status === 404 ) {
355
335
throw new NotFoundError ( message ) ;
356
336
}
337
+
338
+ // GitHub returns a 403 response with a couple of headers indicating rate
339
+ // limit status. See more in the GitHub docs:
340
+ // https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting
341
+ if (
342
+ response . status === 403 &&
343
+ response . headers . get ( 'X-RateLimit-Remaining' ) === '0'
344
+ ) {
345
+ message += ' (rate limit exceeded)' ;
346
+ }
347
+
357
348
throw new Error ( message ) ;
358
349
}
359
350
0 commit comments