@@ -77,8 +77,17 @@ export default defineNitroPlugin(nitroApp => {
7777 const method = options . method || 'GET'
7878 const cacheKey = generateFetchCacheKey ( url , method , options . body )
7979
80- // Try to get cached response
81- const cached = await storage . getItem < CachedFetchEntry < T > > ( cacheKey )
80+ // Try to get cached response (with error handling for storage failures)
81+ let cached : CachedFetchEntry < T > | null = null
82+ try {
83+ cached = await storage . getItem < CachedFetchEntry < T > > ( cacheKey )
84+ } catch ( error ) {
85+ // Storage read failed (e.g., ENOENT on misconfigured storage)
86+ // Log and continue without cache
87+ if ( import . meta. dev ) {
88+ console . warn ( `[fetch-cache] Storage read failed for ${ url } :` , error )
89+ }
90+ }
8291
8392 if ( cached ) {
8493 if ( ! isCacheEntryStale ( cached ) ) {
@@ -126,14 +135,23 @@ export default defineNitroPlugin(nitroApp => {
126135 }
127136
128137 const data = ( await $fetch ( url , options as Parameters < typeof $fetch > [ 1 ] ) ) as T
129- const entry : CachedFetchEntry < T > = {
130- data,
131- status : 200 ,
132- headers : { } ,
133- cachedAt : Date . now ( ) ,
134- ttl,
138+
139+ // Try to cache the response (non-blocking, with error handling)
140+ try {
141+ const entry : CachedFetchEntry < T > = {
142+ data,
143+ status : 200 ,
144+ headers : { } ,
145+ cachedAt : Date . now ( ) ,
146+ ttl,
147+ }
148+ await storage . setItem ( cacheKey , entry )
149+ } catch ( error ) {
150+ // Storage write failed - log but don't fail the request
151+ if ( import . meta. dev ) {
152+ console . warn ( `[fetch-cache] Storage write failed for ${ url } :` , error )
153+ }
135154 }
136- await storage . setItem ( cacheKey , entry )
137155
138156 return data
139157 }
0 commit comments