1
1
import fs from 'fs'
2
2
import path from 'path'
3
3
import slash from 'slash'
4
+ import statsd from '../lib/statsd.js'
4
5
import {
5
6
firstVersionDeprecatedOnNewSite ,
6
7
lastVersionWithoutArchivedRedirectsFile ,
@@ -113,8 +114,16 @@ export default async function archivedEnterpriseVersions(req, res, next) {
113
114
}
114
115
}
115
116
116
- try {
117
- const r = await got ( getProxyPath ( req . path , requestedVersion ) )
117
+ const statsdTags = [ `version:${ requestedVersion } ` ]
118
+ const doGet = ( ) =>
119
+ got ( getProxyPath ( req . path , requestedVersion ) , {
120
+ throwHttpErrors : false ,
121
+ } )
122
+ const r = await statsd . asyncTimer ( doGet , 'archive_enterprise_proxy' , [
123
+ ...statsdTags ,
124
+ `path:${ req . path } ` ,
125
+ ] ) ( )
126
+ if ( r . statusCode === 200 ) {
118
127
res . set ( 'x-robots-tag' , 'noindex' )
119
128
120
129
// make stubbed redirect files (which exist in versions <2.13) redirect with a 301
@@ -126,19 +135,25 @@ export default async function archivedEnterpriseVersions(req, res, next) {
126
135
127
136
res . set ( 'content-type' , r . headers [ 'content-type' ] )
128
137
return res . send ( r . body )
129
- } catch ( err ) {
130
- for ( const fallbackRedirect of getFallbackRedirects ( req , requestedVersion ) || [ ] ) {
131
- try {
132
- await got ( getProxyPath ( fallbackRedirect , requestedVersion ) )
133
- cacheControl ( res )
134
- return res . redirect ( 301 , fallbackRedirect )
135
- } catch ( err ) {
136
- // noop
137
- }
138
- }
138
+ }
139
139
140
- return next ( )
140
+ for ( const fallbackRedirect of getFallbackRedirects ( req , requestedVersion ) || [ ] ) {
141
+ const doGet = ( ) =>
142
+ got ( getProxyPath ( fallbackRedirect , requestedVersion ) , {
143
+ throwHttpErrors : false ,
144
+ } )
145
+
146
+ const r = await statsd . asyncTimer ( doGet , 'archive_enterprise_proxy_fallback' , [
147
+ ...statsdTags ,
148
+ `fallback:${ fallbackRedirect } ` ,
149
+ ] ) ( )
150
+ if ( r . statusCode === 200 ) {
151
+ cacheControl ( res )
152
+ return res . redirect ( 301 , fallbackRedirect )
153
+ }
141
154
}
155
+
156
+ return next ( )
142
157
}
143
158
144
159
// paths are slightly different depending on the version
0 commit comments