@@ -120,15 +120,24 @@ export default async function archivedEnterpriseVersions(
120120 return res . safeRedirect ( redirectCode , redirectTo )
121121 }
122122
123- const redirectJson = ( await getRemoteJSON ( getProxyPath ( 'redirects.json' , requestedVersion ) , {
124- retry : retryConfiguration ,
125- // This is allowed to be different compared to the other requests
126- // we make because downloading the `redirects.json` once is very
127- // useful because it caches so well.
128- // And, as of 2021 that `redirects.json` is 10MB so it's more likely
129- // to time out.
130- timeout : { response : 1000 } ,
131- } ) ) as Record < string , string >
123+ let redirectJson : Record < string , string >
124+ try {
125+ redirectJson = ( await getRemoteJSON ( getProxyPath ( 'redirects.json' , requestedVersion ) , {
126+ retry : retryConfiguration ,
127+ // This is allowed to be different compared to the other requests
128+ // we make because downloading the `redirects.json` once is very
129+ // useful because it caches so well.
130+ // And, as of 2021 that `redirects.json` is 10MB so it's more likely
131+ // to time out.
132+ timeout : { response : 1000 } ,
133+ } ) ) as Record < string , string >
134+ } catch ( err ) {
135+ logger . error ( 'Failed to fetch archived redirects.json' , {
136+ version : requestedVersion ,
137+ error : err instanceof Error ? err : new Error ( String ( err ) ) ,
138+ } )
139+ throw err
140+ }
132141 if ( ! req . context ) throw new Error ( 'No context on request' )
133142 const [ language , withoutLanguage ] = splitPathByLanguage ( req . path , req . context . userLanguage )
134143 const newRedirectTo = redirectJson [ withoutLanguage ]
@@ -179,15 +188,24 @@ export default async function archivedEnterpriseVersions(
179188 versionSatisfiesRange ( requestedVersion , `>${ lastVersionWithoutArchivedRedirectsFile } ` ) &&
180189 ! deprecatedWithFunctionalRedirects . includes ( requestedVersion )
181190 ) {
182- const redirectJson = ( await getRemoteJSON ( getProxyPath ( 'redirects.json' , requestedVersion ) , {
183- retry : retryConfiguration ,
184- // This is allowed to be different compared to the other requests
185- // we make because downloading the `redirects.json` once is very
186- // useful because it caches so well.
187- // And, as of 2021 that `redirects.json` is 10MB so it's more likely
188- // to time out.
189- timeout : { response : 1000 } ,
190- } ) ) as Record < string , string >
191+ let redirectJson : Record < string , string >
192+ try {
193+ redirectJson = ( await getRemoteJSON ( getProxyPath ( 'redirects.json' , requestedVersion ) , {
194+ retry : retryConfiguration ,
195+ // This is allowed to be different compared to the other requests
196+ // we make because downloading the `redirects.json` once is very
197+ // useful because it caches so well.
198+ // And, as of 2021 that `redirects.json` is 10MB so it's more likely
199+ // to time out.
200+ timeout : { response : 1000 } ,
201+ } ) ) as Record < string , string >
202+ } catch ( err ) {
203+ logger . error ( 'Failed to fetch archived redirects.json' , {
204+ version : requestedVersion ,
205+ error : err instanceof Error ? err : new Error ( String ( err ) ) ,
206+ } )
207+ throw err
208+ }
191209
192210 // make redirects found via redirects.json redirect with a 301
193211 if ( redirectJson [ req . path ] ) {
@@ -230,12 +248,20 @@ export default async function archivedEnterpriseVersions(
230248
231249 // Log errors for non-200 responses to help identify issues with archived content
232250 if ( r . status !== 200 ) {
251+ let upstreamBody : string | undefined
252+ try {
253+ upstreamBody = await r . text ( )
254+ } catch {
255+ // ignore — body reading failure shouldn't affect error handling
256+ }
233257 logger . error ( 'Failed to fetch archived enterprise content' , {
234258 version : requestedVersion ,
235259 path : req . path ,
236260 status : r . status ,
261+ statusText : r . statusText ,
237262 responseTime : `${ responseTime } ms` ,
238263 url : getProxyPath ( req . path , requestedVersion ) ,
264+ upstreamBody : upstreamBody ?. slice ( 0 , 500 ) ,
239265 } )
240266 }
241267
0 commit comments