@dewib/xhr-cache
Advanced tools
Comparing version 1.0.0 to 1.0.2
@@ -35,4 +35,31 @@ import { dirname } from 'path' | ||
return axios(config).catch((err) => { | ||
return { data: request.catch } || Promise.reject(err) | ||
return axios(config).then((response) => { | ||
if (!response.data) { | ||
const error = `${libPrefix} Response from ${request.url} is empty` | ||
if (typeof request.catch !== 'undefined') { | ||
error += ` using provided default value ${request.catch}` | ||
/* eslint-disable-next-line */ | ||
console.error(error) | ||
return { data: request.catch } | ||
} | ||
// Returning default value to avoid null value | ||
/* eslint-disable-next-line */ | ||
console.error(`${error} using default value {}`) | ||
return { data: {} } | ||
} | ||
return response | ||
}).catch((err) => { | ||
if (typeof request.catch !== 'undefined') { | ||
/* eslint-disable-next-line */ | ||
console.error(`${libPrefix} Error on fetching resource ${request.url} returning catch value: ${err}`) | ||
return { data: request.catch } | ||
} | ||
return Promise.reject(err) | ||
}) | ||
@@ -45,3 +72,9 @@ } | ||
return JSON.parse(fs.readFileSync(path, 'UTF-8')) | ||
try { | ||
return JSON.parse(fs.readFileSync(path, 'UTF-8')) | ||
} catch (err) { | ||
console.err(`${libPrefix} Unable to parse JSON from ${path}`) | ||
return {} | ||
} | ||
} | ||
@@ -48,0 +81,0 @@ |
{ | ||
"name": "@dewib/xhr-cache", | ||
"version": "1.0.0", | ||
"version": "1.0.2", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Cache api resources and serve it as static resource", |
@@ -1,2 +0,2 @@ | ||
# XHR Cache Module | ||
# XHR Cache Module v1.0.2 | ||
@@ -20,3 +20,3 @@ > Cache application/json api resources and serve it as static resource | ||
[ | ||
'xhr-cache' | ||
'@dewib/xhr-cache' | ||
] | ||
@@ -45,3 +45,4 @@ ] | ||
url: 'http://www.mocky.io/v2/5d9e4c643200002a00329d0a' | ||
} | ||
}, | ||
catch: [] // Value used if request failed or response is empty | ||
} | ||
@@ -55,6 +56,8 @@ ] | ||
XHR cache expose routes to refresh a resource manually. | ||
XHR cache expose routes to refresh a resource manually | ||
All routes are exposed during nuxtjs start with the specific path: | ||
All routes are exposed once the first called has been made to the resource or if the init resource option is set to true | ||
The refresh route is generated like this: | ||
```javascript | ||
@@ -64,3 +67,3 @@ path.join( | ||
'/cache/refresh/', | ||
id // Generated id of resource | ||
id) // Generated id of resource | ||
``` | ||
@@ -67,0 +70,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
64580
28
1162
133
13
14