@@ -83,7 +83,6 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
8383 previewModeId,
8484 } = msg ;
8585 const protocol = host . includes ( "localhost" ) ? "http" : "https" ;
86- console . log ( 'previewModeId' , previewModeId ) ;
8786
8887 const response = await this . service . fetch ( `${ protocol } ://${ host } ${ url } ` , {
8988 method : "HEAD" ,
@@ -95,12 +94,15 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
9594 } ) ;
9695 // Now we need to handle errors from the fetch
9796 if ( response . status === 200 && response . headers . get ( "x-nextjs-cache" ) !== "REVALIDATED" ) {
98- // Something is very wrong here, it means that either the page is not ISR/SSG (and we shouldn't be here) or the `x-prerender-revalidate` header is not correct (and it should not happen either)
97+ // TODO: when restoring from the failed state during a new deployment, previewModeId will be different and we'll be in this case. Figure out how to handle this.
98+ this . routeInFailedState . delete ( msg . MessageDeduplicationId ) ;
9999 throw new FatalError (
100100 `The revalidation for ${ host } ${ url } cannot be done. This error should never happen.`
101101 ) ;
102102 } else if ( response . status === 404 ) {
103103 // The page is not found, we should not revalidate it
104+ // We remove the route from the failed state because it might be expected (i.e. a route that was deleted)
105+ this . routeInFailedState . delete ( msg . MessageDeduplicationId ) ;
104106 throw new IgnorableError (
105107 `The revalidation for ${ host } ${ url } cannot be done because the page is not found. It's either expected or an error in user code itself`
106108 ) ;
@@ -113,6 +115,10 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
113115 } else if ( response . status !== 200 ) {
114116 // TODO: check if we need to handle cloudflare specific status codes/errors
115117 // An unknown error occurred, most likely from something in user code like missing auth in the middleware
118+
119+ // We probably want to retry in this case as well
120+ await this . addToFailedState ( msg ) ;
121+
116122 throw new RecoverableError ( `An unknown error occurred while revalidating ${ host } ${ url } ` ) ;
117123 }
118124 // Everything went well, we can update the sync table
@@ -122,6 +128,8 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
122128 // We cannot use the deduplication id because it's not unique per route - every time a route is revalidated, the deduplication id is different.
123129 `${ host } ${ url } `
124130 ) ;
131+ // If everything went well, we can remove the route from the failed state
132+ this . routeInFailedState . delete ( msg . MessageDeduplicationId ) ;
125133 } catch ( e ) {
126134 // Do we want to propagate the error to the calling worker?
127135 if ( ! isOpenNextError ( e ) ) {
0 commit comments