I am using the times() method of async.js (https://caolan.github.io/async/docs.html#times).
It basically calls an async function X amount of times, and then once every async function resolves, it gives you the opportunity to consolidate your results in one callback.
I notice when I mimic a 404 or any error, I can pass the error to the final callback and either render a visual prompt to the user, log it to the server, etc.
Whenever I force an error, I always get an error in my console also:
Uncaught (in promise) Error: Unexpected status code [404] on URL...
Am I doing something wrong in terms of handling this error (Should I actually not being seeing this if I was handling the error correctly)?
My async function, and then my times()
implementation basically looks like:
var getPrismicStories = function(pageNumber, callback) {
let stories = [];
Prismic.api("https://myendpoint.prismic.io/api",{accessToken}).then((api) => {
return api.query(Prismic.Predicates.any('document.type', ['blog-posts','video-posts']),{pageSize : 100, page : pageNumber, orderings : '[document.first_publication_date desc]',after:lastInitialStoryId})
}).then((prismicResponse) => {
stories = prismicResponse.results;
callback(null, stories);
}).catch((error) => {callback(error,stories)});
};
times(4, (i,next) => {
getPrismicStories(++i, function(err, stories) {
next(err, stories);
});
}, function(err, allStories) {
if(err){
console.error(err);
}
doSomethingWithFetchResults(allStories);
});
I am forcing the 404 for instance, by requesting an incorrect URL name ("notmyendpoint.prismic.io/api"
).