I'm making multiple GET requests by building the URLs dynamically.
For any error, I want to grab the value of response.config.url, process it, and push the resulting value into an object.
The code below works fine when I only get ONE error.
When more than one error is returned, only the value from the last error is pushed into the object. I guess that's because it overwrites the previous one(s).
How do I prevent that? How do I make sure that all values get pushed into the object when there is more than one error?
(Note: annotation is an array of strings I get from an input field; _ is lodash)
function checkVariants(annotation) {
var lemmas = annotation.text.split(' ');
var results = [];
var words = [];
for (var i = 0; i < lemmas.length; ++i) {
var urlLemmas = encodeURIComponent(lemmas[i]).toLowerCase();
results.push(urlLemmas);
$http({
method: 'GET',
url: 'https://xxxxxxx.org/variants/' + results[i] + '.txt'
}).then(function successCallback(response) {
console.log('Success: ', response.status)
}, function errorCallback(response) {
var url = response.config.url;
words = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));
_.extend(annotation, {
variants: words
});
})
}
}