Skip to content

Commit 12225e0

Browse files
committed
MOBILE-2169 errors: Improve errors when offline
1 parent ad4abf4 commit 12225e0

File tree

29 files changed

+111
-95
lines changed

29 files changed

+111
-95
lines changed

www/addons/files/controllers/list.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ angular.module('mm.addons.files')
4949
return promise.then(function(files) {
5050
$scope.files = files.entries;
5151
$scope.count = files.count;
52-
}).catch(function() {
53-
$mmUtil.showErrorModal('mma.files.couldnotloadfiles', true);
52+
}).catch(function(error) {
53+
$mmUtil.showErrorModalDefault(error, 'mma.files.couldnotloadfiles', true);
54+
return $q.reject();
5455
});
5556
}
5657

www/addons/files/services/files.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,18 @@ angular.module('mm.addons.files')
7171
* - linkId: A hash of the file parameters.
7272
*/
7373
self.getFiles = function(params) {
74-
var deferred = $q.defer(),
75-
options = {};
74+
var options = {};
7675

7776
options.cacheKey = getFilesListCacheKey(params);
7877

79-
$mmSite.read('core_files_get_files', params, options).then(function(result) {
78+
return $mmSite.read('core_files_get_files', params, options).then(function(result) {
8079
var data = {
8180
entries: [],
8281
count: 0
8382
};
8483

8584
if (typeof result.files == 'undefined') {
86-
deferred.reject();
87-
return;
85+
return $q.reject();
8886
}
8987

9088
angular.forEach(result.files, function(entry) {
@@ -109,27 +107,13 @@ angular.module('mm.addons.files')
109107

110108
entry.link = JSON.stringify(entry.link);
111109
entry.linkId = md5.createHash(entry.link);
112-
// entry.localpath = "";
113-
114-
// if (!entry.isdir && entry.url) {
115-
// // TODO Check $mmSite.
116-
// var uniqueId = $mmSite.id + "-" + md5.createHash(entry.url);
117-
// var path = MM.db.get("files", uniqueId);
118-
// if (path) {
119-
// entry.localpath = path.get("localpath");
120-
// }
121-
// }
122110

123111
data.count += 1;
124112
data.entries.push(entry);
125113
});
126114

127-
deferred.resolve(data);
128-
}, function() {
129-
deferred.reject();
115+
return data;
130116
});
131-
132-
return deferred.promise;
133117
};
134118

135119
/**

www/addons/mod/assign/services/handlers.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ angular.module('mm.addons.mod_assign')
2121
* @ngdoc service
2222
* @name $mmaModAssignHandlers
2323
*/
24-
.factory('$mmaModAssignHandlers', function($mmCourse, $mmaModAssign, $state, $mmContentLinksHelper, $mmUtil, mmCoreDownloading,
24+
.factory('$mmaModAssignHandlers', function($mmCourse, $mmaModAssign, $state, $mmContentLinksHelper, $mmUtil, mmCoreDownloading, $q,
2525
mmCoreNotDownloaded, mmCoreOutdated, $mmEvents, mmCoreEventPackageStatusChanged, $mmSite, mmaModAssignComponent,
2626
$mmCoursePrefetchDelegate, $mmaModAssignPrefetchHandler, $mmaModAssignSync) {
2727
var self = {};
@@ -102,9 +102,10 @@ angular.module('mm.addons.mod_assign')
102102
// We need to call getDownloadSize, the package might have been updated.
103103
$mmaModAssignPrefetchHandler.getDownloadSize(module, courseId).then(function(size) {
104104
$mmUtil.confirmDownloadSize(size).then(function() {
105-
$mmaModAssignPrefetchHandler.prefetch(module, courseId).catch(function() {
105+
return $mmaModAssignPrefetchHandler.prefetch(module, courseId).catch(function(error) {
106106
if (!$scope.$$destroyed) {
107-
$mmUtil.showErrorModal('mm.core.errordownloading', true);
107+
$mmUtil.showErrorModalDefault(error, 'mm.core.errordownloading', true);
108+
return $q.reject();
108109
}
109110
});
110111
}).catch(function() {

www/addons/mod/book/controllers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ angular.module('mm.addons.mod_book')
5656
$mmCourse.checkModuleCompletion(courseId, module.completionstatus);
5757
}
5858
});
59-
}).catch(function() {
60-
$mmUtil.showErrorModal('mma.mod_book.errorchapter', true);
59+
}).catch(function(error) {
60+
$mmUtil.showErrorModalDefault(error, 'mma.mod_book.errorchapter', true);
6161
return $q.reject();
6262
}).finally(function() {
6363
$scope.loaded = true;

www/addons/mod/choice/services/handlers.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ angular.module('mm.addons.mod_choice')
2121
* @ngdoc service
2222
* @name $mmaModChoiceHandlers
2323
*/
24-
.factory('$mmaModChoiceHandlers', function($mmCourse, $mmaModChoice, $state, $mmContentLinksHelper, $mmUtil, $mmEvents, $mmSite,
24+
.factory('$mmaModChoiceHandlers', function($mmCourse, $mmaModChoice, $state, $mmContentLinksHelper, $mmUtil, $mmEvents, $mmSite, $q,
2525
$mmaModChoicePrefetchHandler, $mmCoursePrefetchDelegate, mmCoreDownloading, mmCoreNotDownloaded, mmCoreOutdated,
2626
mmaModChoiceComponent, mmCoreEventPackageStatusChanged, mmCoreDownloaded, $mmaModChoiceSync) {
2727
var self = {};
@@ -103,9 +103,10 @@ angular.module('mm.addons.mod_choice')
103103
// Get download size to ask for confirm if it's high.
104104
$mmaModChoicePrefetchHandler.getDownloadSize(module, courseId).then(function(size) {
105105
$mmUtil.confirmDownloadSize(size).then(function() {
106-
$mmaModChoicePrefetchHandler.prefetch(module, courseId).catch(function() {
106+
return $mmaModChoicePrefetchHandler.prefetch(module, courseId).catch(function(error) {
107107
if (!$scope.$$destroyed) {
108-
$mmUtil.showErrorModal('mm.core.errordownloading', true);
108+
$mmUtil.showErrorModalDefault(error, 'mm.core.errordownloading', true);
109+
return $q.reject();
109110
}
110111
});
111112
}).catch(function() {

www/addons/mod/data/services/handlers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ angular.module('mm.addons.mod_data')
102102
// We need to call getDownloadSize, the package might have been updated.
103103
$mmaModDataPrefetchHandler.getDownloadSize(module, courseId).then(function(size) {
104104
$mmUtil.confirmDownloadSize(size).then(function() {
105-
$mmaModDataPrefetchHandler.prefetch(module, courseId).catch(function(error) {
105+
return $mmaModDataPrefetchHandler.prefetch(module, courseId).catch(function(error) {
106106
if (!$scope.$$destroyed) {
107107
$mmUtil.showErrorModalDefault(error, 'mm.core.errordownloading', true);
108+
return $q.reject();
108109
}
109110
});
110111
}).catch(function() {

www/addons/mod/feedback/services/handlers.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ angular.module('mm.addons.mod_feedback')
2222
* @name $mmaModFeedbackHandlers
2323
*/
2424
.factory('$mmaModFeedbackHandlers', function($mmCourse, $mmaModFeedback, $state, $mmContentLinksHelper, $mmUtil, $mmEvents, $mmSite,
25-
mmaModFeedbackComponent, $mmaModFeedbackPrefetchHandler, mmCoreDownloading, mmCoreNotDownloaded, $mmaModFeedbackSync,
25+
mmaModFeedbackComponent, $mmaModFeedbackPrefetchHandler, mmCoreDownloading, mmCoreNotDownloaded, $mmaModFeedbackSync, $q,
2626
mmCoreEventPackageStatusChanged, mmCoreOutdated, $mmCoursePrefetchDelegate, $mmContentLinkHandlerFactory) {
2727
var self = {};
2828

@@ -102,9 +102,10 @@ angular.module('mm.addons.mod_feedback')
102102
// We need to call getDownloadSize, the package might have been updated.
103103
$mmaModFeedbackPrefetchHandler.getDownloadSize(module, courseId).then(function(size) {
104104
$mmUtil.confirmDownloadSize(size).then(function() {
105-
$mmaModFeedbackPrefetchHandler.prefetch(module, courseId).catch(function() {
105+
return $mmaModFeedbackPrefetchHandler.prefetch(module, courseId).catch(function(error) {
106106
if (!$scope.$$destroyed) {
107-
$mmUtil.showErrorModal('mm.core.errordownloading', true);
107+
$mmUtil.showErrorModalDefault(error, 'mm.core.errordownloading', true);
108+
return $q.reject();
108109
}
109110
});
110111
}).catch(function() {

www/addons/mod/forum/services/handlers.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ angular.module('mm.addons.mod_forum')
2121
* @ngdoc service
2222
* @name $mmaModForumHandlers
2323
*/
24-
.factory('$mmaModForumHandlers', function($mmCourse, $mmaModForum, $state, $mmUtil, $mmContentLinksHelper, $mmEvents, $mmSite,
24+
.factory('$mmaModForumHandlers', function($mmCourse, $mmaModForum, $state, $mmUtil, $mmContentLinksHelper, $mmEvents, $mmSite, $q,
2525
$mmaModForumPrefetchHandler, $mmCoursePrefetchDelegate, mmCoreDownloading, mmCoreNotDownloaded, mmCoreOutdated,
2626
mmaModForumComponent, mmCoreEventPackageStatusChanged, $mmaModForumSync, $mmContentLinkHandlerFactory) {
2727
var self = {};
@@ -110,9 +110,10 @@ angular.module('mm.addons.mod_forum')
110110
// Get download size to ask for confirm if it's high.
111111
$mmaModForumPrefetchHandler.getDownloadSize(module, courseId).then(function(size) {
112112
$mmUtil.confirmDownloadSize(size).then(function() {
113-
$mmaModForumPrefetchHandler.prefetch(module, courseId).catch(function() {
113+
return $mmaModForumPrefetchHandler.prefetch(module, courseId).catch(function(error) {
114114
if (!$scope.$$destroyed) {
115-
$mmUtil.showErrorModal('mm.core.errordownloading', true);
115+
$mmUtil.showErrorModalDefault(error, 'mm.core.errordownloading', true);
116+
return $q.reject();
116117
}
117118
});
118119
}).catch(function() {

www/addons/mod/glossary/controllers/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ angular.module('mm.addons.mod_glossary')
168168
var promises = [];
169169
// Ignore search mode that is not set yet.
170170
if (fetchMode != 'search' || $scope.searchQuery) {
171-
var args = angular.extend([], fetchArguments);
172-
promises.push(fetchInvalidate.apply(this, args));
171+
if (fetchInvalidate) {
172+
var args = angular.extend([], fetchArguments);
173+
promises.push(fetchInvalidate.apply(this, args));
174+
}
173175
promises.push($mmaModGlossary.invalidateCourseGlossaries(courseId));
174176
}
175177
if (glossary && glossary.id) {
@@ -356,9 +358,9 @@ angular.module('mm.addons.mod_glossary')
356358
$scope.canLoadMore = (limitFrom + limitNum) < result.count;
357359

358360
$scope.showNoEntries = ($scope.entries.length + $scope.offlineEntries.length) <= 0;
359-
}).catch(function() {
361+
}).catch(function(error) {
360362
if (append) {
361-
$mmUtil.showErrorModal('mma.mod_glossary.errorloadingentries', true);
363+
$mmUtil.showErrorModalDefault(error, 'mma.mod_glossary.errorloadingentries', true);
362364
}
363365
$scope.canLoadMore = false; // Set to false to prevent infinite calls with infinite-loading.
364366
return $q.reject();

www/addons/mod/glossary/services/handlers.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ angular.module('mm.addons.mod_glossary')
105105
// Get download size to ask for confirm if it's high.
106106
$mmaModGlossaryPrefetchHandler.getDownloadSize(module, courseId).then(function(size) {
107107
$mmUtil.confirmDownloadSize(size).then(function() {
108-
$mmaModGlossaryPrefetchHandler.prefetch(module, courseId).catch(function() {
108+
return $mmaModGlossaryPrefetchHandler.prefetch(module, courseId).catch(function(error) {
109109
if (!$scope.$$destroyed) {
110-
$mmUtil.showErrorModal('mm.core.errordownloading', true);
110+
$mmUtil.showErrorModalDefault(error, 'mm.core.errordownloading', true);
111+
return $q.reject();
111112
}
112113
});
113114
}).catch(function() {

0 commit comments

Comments
 (0)