diff --git a/www/core/components/course/lang/en.json b/www/core/components/course/lang/en.json index 8c6cb9d35c1..4843f66dcdf 100644 --- a/www/core/components/course/lang/en.json +++ b/www/core/components/course/lang/en.json @@ -13,6 +13,7 @@ "couldnotloadsections": "Could not load the sections. Please try again later.", "downloadcourse": "Download course", "errordownloadingcourse": "Error downloading course.", + "errordownloadingcoursewithname": "
Error downloading course: {{name}}
{{error}}
", "errordownloadingsection": "Error downloading section.", "errorgetmodule": "Error getting activity data.", "hiddenfromstudents": "Hidden from students", diff --git a/www/core/components/course/services/helper.js b/www/core/components/course/services/helper.js index 707ad61d08d..255b0a85f63 100644 --- a/www/core/components/course/services/helper.js +++ b/www/core/components/course/services/helper.js @@ -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. + })); } }); @@ -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. diff --git a/www/core/lib/util.js b/www/core/lib/util.js index 6f7cfb720a3..0f26744ec0c 100644 --- a/www/core/lib/util.js +++ b/www/core/lib/util.js @@ -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)); } } });