Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function fetcher (config) {
const mergedConfig = Object.assign({}, defaultConfig, config);
const url = mergedConfig.api() + mergedConfig.url;
log('Fetching:', url);
const req = fetch(url, mergedConfig)
.then(response => {
remove(mergedConfig.url);
if (response.status >= 400) {
if(mergedConfig.failure) {
mergedConfig.failure(response);
} else {
throw new Error('Bad response from server');
}
}
return response.json().then(data => {
return {
postsPaginationTotal: response.headers.get('X-WP-TotalPages'),
eventsPaginationTotal: response.headers.get('X-WP-TotalPages'),
archivedEventsPaginationTotal: response.headers.get('X-WP-TotalPages'),
data: data
}