Skip to content

Commit 9c44285

Browse files
committed
JI-942 Add optional improved error handling
1 parent 6364550 commit 9c44285

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

scripts/h5peditor-editor.js

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,46 @@ ns.Editor.prototype.getParams = function (notFormSubmit) {
281281
*
282282
* @alias H5PEditor.Editor#getContent
283283
* @param {Function} submit Callback to submit the content data
284+
* @param {Function} [error] Callback on failure
284285
*/
285-
ns.Editor.prototype.getContent = function (submit) {
286+
ns.Editor.prototype.getContent = function (submit, error) {
286287
const iframeEditor = this.iframeWindow.H5PEditor;
287288

289+
if (!this.selector.form) {
290+
if (error) {
291+
error('content-not-selected');
292+
}
293+
return;
294+
}
295+
288296
const content = {
289297
title: this.isMainTitleSet(),
290298
library: this.getLibrary(),
291299
params: this.getParams()
292300
};
293301

294-
if (!content.title || !content.library || !content.params || !content.params.params) {
302+
if (!content.title) {
303+
if (error) {
304+
error('missing-title');
305+
}
306+
return;
307+
}
308+
if (!content.library) {
309+
if (error) {
310+
error('missing-library');
311+
}
312+
return;
313+
}
314+
if (!content.params) {
315+
if (error) {
316+
error('missing-params');
317+
}
318+
return;
319+
}
320+
if (!content.params.params) {
321+
if (error) {
322+
error('missing-params-params');
323+
}
295324
return;
296325
}
297326

@@ -305,7 +334,12 @@ ns.Editor.prototype.getContent = function (submit) {
305334
if (upgradeLibrary) {
306335
// We need to run content upgrade before saving
307336
iframeEditor.upgradeContent(library, upgradeLibrary, content.params, function (err, result) {
308-
if (!err) {
337+
if (err) {
338+
if (error) {
339+
error(err);
340+
}
341+
}
342+
else {
309343
content.library = iframeEditor.ContentType.getNameVersionString(upgradeLibrary);
310344
content.params = result;
311345
submit(content);

0 commit comments

Comments
 (0)