To keep cache response & api response consistent, alter call chain

This commit is contained in:
2022-09-25 13:25:48 +02:00
parent 0124a3c8bb
commit 9e77fe8801

View File

@@ -194,9 +194,12 @@ class Plex {
return new Promise((resolve, reject) =>
this.cache
.get(cacheKey)
.catch(() => fetch(url, options)) // else fetch fresh data
.then(successfullResponse)
.then(results => this.cache.set(cacheKey, results, 21600)) // 6 hours
.catch(error => {
// else fetch fresh data
return fetch(url, options)
.then(successfullResponse)
.then(results => this.cache.set(cacheKey, results, 21600)); // 6 hours
})
.then(mapResults)
.then(resolve)
.catch(error => {