in public/src/js/modules/content-api.js [256:304]
function fetchLatest (options) {
var propName, term, filter;
options = _.extend({
article: '',
term: '',
filter: '',
filterType: '',
page: 1,
pageSize: CONST.searchPageSize || 25,
isDraft: true
}, options);
term = options.term;
filter = options.filter;
let url = (options.isDraft ? CONST.apiSearchBase : CONST.apiLiveBase) + '/';
if (options.article) {
term = options.article;
propName = 'content';
url += term + '?' + CONST.apiSearchParams;
} else {
term = encodeURIComponent(term.trim());
propName = 'results';
url += (options.isDraft ? 'content/scheduled?' : 'search?') + CONST.apiSearchParams;
url += options.isDraft ?
'&order-by=oldest&from-date=' + dateYyyymmdd() :
'&order-by=newest';
url += '&page-size=' + options.pageSize;
url += '&page=' + options.page;
url += term ? '&q=' + term : '';
url += filter ? '&' + options.filterType + '=' + encodeURIComponent(filter) : '';
}
return request({
url: url
}).then(function (data) {
return handleFetchLatestResponse(data, propName, term || filter);
}, function (xhr) {
if (xhr.status === 200) {
const parsed = JSON.parse(xhr.responseText);
if (parsed.json) {
mediator.emit('capi:error', parsed.errors[0]);
return handleFetchLatestResponse(parsed.json, propName, term || filter);
}
}
throw new Error('Content API error (' + xhr.status + '). Content is currently unavailable');
});
}