File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,16 @@ export class Hit {
3333 this . data = data ;
3434 this . etag = existingEtag ?? generateEtag ( JSON . stringify ( data ) ) ;
3535 }
36+
37+ withError ( error : string , consecutiveErrors : number ) : Hit {
38+ const hit = new Hit ( this . cacheName , this . data , this . etag ) ;
39+ hit . cached = this . cached ;
40+ hit . created = this . created ;
41+ hit . error = error ;
42+ hit . errorTime = new Date ( ) ;
43+ hit . consecutiveErrors = consecutiveErrors ;
44+ return hit ;
45+ }
3646}
3747
3848export class Miss {
Original file line number Diff line number Diff line change @@ -63,10 +63,7 @@ export class Cacheism {
6363 const errorMessage = err instanceof Error ? err . toString ( ) : String ( err ) ;
6464
6565 if ( status >= Status . cacheOnFail && hasCache && existing . isHit ) {
66- response = existing ;
67- response . error = errorMessage ;
68- response . errorTime = new Date ( ) ;
69- response . consecutiveErrors ++ ;
66+ response = existing . withError ( errorMessage , existing . consecutiveErrors + 1 ) ;
7067 } else {
7168 response = new Miss ( name , errorMessage , existing . consecutiveErrors + 1 ) ;
7269 }
You can’t perform that action at this time.
0 commit comments