@@ -159,25 +159,52 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
159
159
const responseHeaders = response . headers ( ) ;
160
160
ctx . log . debug ( `Response headers for ${ requestUrl } : ${ JSON . stringify ( responseHeaders , null , 2 ) } ` ) ;
161
161
}
162
- let data = {
163
- statusCode : `${ response . status ( ) } ` ,
164
- url : requestUrl ,
165
- resourceType : request . resourceType ( ) ,
166
- }
167
-
168
- if ( ! discoveryErrors . browsers [ globalBrowser ] ) {
169
- discoveryErrors . browsers [ globalBrowser ] = { } ; }
170
-
171
- // Check if the discoveryErrors.browsers[globalBrowser] exists, and if not, initialize it
172
- if ( discoveryErrors . browsers [ globalBrowser ] && ! discoveryErrors . browsers [ globalBrowser ] [ globalViewport ] ) {
173
- discoveryErrors . browsers [ globalBrowser ] [ globalViewport ] = [ ] ;
174
- }
175
162
176
- // Dynamically push the data into the correct browser and viewport
177
- if ( discoveryErrors . browsers [ globalBrowser ] ) {
178
- discoveryErrors . browsers [ globalBrowser ] [ globalViewport ] ?. push ( data ) ;
163
+ let responseOfRetry , bodyOfRetry
164
+ ctx . log . debug ( `Resource had a disallowed status ${ requestUrl } fetching from server again` ) ;
165
+ responseOfRetry = await page . request . fetch ( request , requestOptions ) ;
166
+ bodyOfRetry = await responseOfRetry . body ( ) ;
167
+
168
+ if ( responseOfRetry && responseOfRetry . status ( ) && ALLOWED_STATUSES . includes ( responseOfRetry . status ( ) ) ) {
169
+ ctx . log . debug ( `Handling request after retry ${ requestUrl } \n - content-type ${ responseOfRetry . headers ( ) [ 'content-type' ] } ` ) ;
170
+ cache [ requestUrl ] = {
171
+ body : bodyOfRetry . toString ( 'base64' ) ,
172
+ type : responseOfRetry . headers ( ) [ 'content-type' ]
173
+ }
174
+ route . fulfill ( {
175
+ status : responseOfRetry . status ( ) ,
176
+ headers : responseOfRetry . headers ( ) ,
177
+ body : bodyOfRetry ,
178
+ } ) ;
179
+ } else {
180
+ ctx . log . debug ( `Resource had a disallowed status for retry as well ${ requestUrl } disallowed status [${ responseOfRetry . status ( ) } ]` ) ;
181
+ if ( responseOfRetry && responseOfRetry . headers ( ) ) {
182
+ const responseHeadersRetry = responseOfRetry . headers ( ) ;
183
+ ctx . log . debug ( `Response headers for ${ requestUrl } : ${ JSON . stringify ( responseHeadersRetry , null , 2 ) } ` ) ;
184
+ }
185
+
186
+ let data = {
187
+ statusCode : `${ responseOfRetry . status ( ) } ` ,
188
+ url : requestUrl ,
189
+ resourceType : request . resourceType ( ) ,
190
+ }
191
+
192
+ if ( ! discoveryErrors . browsers [ globalBrowser ] ) {
193
+ discoveryErrors . browsers [ globalBrowser ] = { } ;
194
+ }
195
+
196
+ // Check if the discoveryErrors.browsers[globalBrowser] exists, and if not, initialize it
197
+ if ( discoveryErrors . browsers [ globalBrowser ] && ! discoveryErrors . browsers [ globalBrowser ] [ globalViewport ] ) {
198
+ discoveryErrors . browsers [ globalBrowser ] [ globalViewport ] = [ ] ;
199
+ }
200
+
201
+ // Dynamically push the data into the correct browser and viewport
202
+ if ( discoveryErrors . browsers [ globalBrowser ] ) {
203
+ discoveryErrors . browsers [ globalBrowser ] [ globalViewport ] ?. push ( data ) ;
204
+ }
179
205
}
180
206
207
+
181
208
} else {
182
209
ctx . log . debug ( `Handling request ${ requestUrl } \n - content-type ${ response . headers ( ) [ 'content-type' ] } ` ) ;
183
210
0 commit comments