Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions www/core/components/course/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"couldnotloadsections": "Could not load the sections. Please try again later.",
"downloadcourse": "Download course",
"errordownloadingcourse": "Error downloading course.",
"errordownloadingcoursewithname": "<p>Error downloading course: {{name}}</p><p>{{error}}</p>",
"errordownloadingsection": "Error downloading section.",
"errorgetmodule": "Error getting activity data.",
"hiddenfromstudents": "Hidden from students",
Expand Down
13 changes: 12 additions & 1 deletion www/core/components/course/services/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,9 @@ angular.module('mm.core.course')
// Prefetch course options.
angular.forEach(courseOptions, function(option) {
if (option.prefetch) {
promises.push($q.when(option.prefetch(course)));
promises.push($q.when(option.prefetch(course)).catch(function() {
// Ignore errors when downloading course options.
}));
}
});

Expand Down Expand Up @@ -978,6 +980,15 @@ angular.module('mm.core.course')
return self.prefetchCourse(course, sections, handlers, siteId);
}).catch(function(error) {
success = false;

// Try to improve the error message, including the course name.
if (course && course.fullname) {
error = $translate.instant('mm.course.errordownloadingcoursewithname', {
name: course.fullname,
error: error || ''
});
}

return $q.reject(error);
}).finally(function() {
// Course downloaded or failed, notify the progress.
Expand Down
10 changes: 7 additions & 3 deletions www/core/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1246,20 +1246,24 @@ angular.module('mm.core')

var count = 0,
failed = false,
error,
deferred = $q.defer();

angular.forEach(promises, function(promise) {
promise.catch(function() {
promise.catch(function(err) {
failed = true;
error = err;
}).finally(function() {
count++;

if (count === promises.length) {
// All promises have finished, reject/resolve.
if (failed) {
deferred.reject();
deferred.reject(error);
} else {
deferred.resolve();
// All the promises have been resolved, $q.all should finish immediately and send back the result
// of all the promises.
deferred.resolve($q.all(promises));
}
}
});
Expand Down