Skip to content

Commit cdf463e

Browse files
Merge pull request #2354 from CanStudios/issue/2351
Fix for trying to access course that does not exists looks like I have no course
2 parents cae3830 + c6e3211 commit cdf463e

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

frontend/src/modules/editor/global/editorDataLoader.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ define(function(require) {
8989
});
9090
}
9191
// fetch all collections
92-
fetchEditorData(courseData, function() {
92+
fetchEditorData(courseData, function(error) {
9393
if(_.isFunction(callback)) callback();
94+
if (error) {
95+
Origin.trigger('editor:failedToLoad');
96+
}
9497
loadingCourseData = false;
9598
Origin.trigger('editor:dataLoaded');
9699
});
@@ -105,13 +108,19 @@ define(function(require) {
105108
* Makes sure all data has been loaded and calls callback
106109
*/
107110
waitForLoad: function(callback) {
111+
var removeEvents = function() {
112+
Origin.off({
113+
'editor:dataPreloaded': done,
114+
'editor:dataLoaded': done,
115+
'editor:failedToLoad': removeEvents
116+
});
117+
};
108118
var done = function() {
109119
if(preloader.hasLoadedData()) {
110-
Origin.off('editor:dataPreloaded', done);
111-
Origin.off('editor:dataLoaded', done);
120+
removeEvents();
112121
callback.apply(this);
113122
}
114-
}
123+
};
115124
// in case we've already loaded
116125
done();
117126

@@ -121,6 +130,7 @@ define(function(require) {
121130
if(!preloader.hasLoadedCourseData()) {
122131
Origin.on('editor:dataLoaded', done);
123132
}
133+
Origin.on('editor:failedToLoad', removeEvents);
124134
},
125135
/**
126136
* Uses the below checks to test loading status
@@ -176,7 +186,10 @@ define(function(require) {
176186
data[collection._type] = true;
177187
if(callback && isAllDataLoaded(data)) callback.apply(this);
178188
},
179-
error: onFetchError
189+
error: function(error) {
190+
onFetchError();
191+
callback(error);
192+
}
180193
});
181194
}
182195
}
@@ -216,6 +229,7 @@ define(function(require) {
216229
type: 'error',
217230
text: Origin.l10n.t('app.errorgeneric')
218231
});
232+
Origin.router.navigateTo('dashboard');
219233
}
220234

221235
/**

0 commit comments

Comments
 (0)