diff --git a/www/common/cryptget.js b/www/common/cryptget.js index b03d756e1..ab707a49b 100644 --- a/www/common/cryptget.js +++ b/www/common/cryptget.js @@ -76,6 +76,9 @@ define([ finish(Session, void 0, rt.getUserDoc()); }; + config.onError = function (info) { + finish(Session, info.error); + }; config.onChannelError = function (info) { finish(Session, info.error); }; diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index af34260a9..71848e36d 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -632,7 +632,12 @@ define([ } }).nThen(function () { Crypt.get(parsed.hash, function (err, val) { - if (err) { throw new Error(err); } + if (err) { + return void cb(err); + } + if (!val) { + return void cb('ENOENT'); + } try { // Try to fix the title before importing the template var parsed = JSON.parse(val); @@ -665,14 +670,14 @@ define([ Crypt.get(parsed.hash, _waitFor(function (err, _val) { if (err) { _waitFor.abort(); - return void cb(); + return void cb(err); } try { val = JSON.parse(_val); fixPadMetadata(val, true); } catch (e) { _waitFor.abort(); - return void cb(); + return void cb(e.message); } }), optsGet); return; @@ -691,7 +696,7 @@ define([ Util.fetch(src, waitFor(function (err, _u8) { if (err) { _waitFor.abort(); - return void waitFor.abort(); + return void cb(err); } u8 = _u8; })); @@ -700,7 +705,7 @@ define([ FileCrypto.decrypt(u8, key, waitFor(function (err, _res) { if (err || !_res.content) { _waitFor.abort(); - return void waitFor.abort(); + return void cb(err); } res = _res; })); diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index f829409dd..7793b48c8 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -1730,7 +1730,9 @@ define([ && $target.parents('#cp-app-drive-content')) { newPath = currentPath; } - if (newPath[0] !== ROOT) { newPath = [ROOT]; } + // XXX Why did we add the following line? + // https://github.com/xwiki-labs/cryptpad/commit/f103a0fb08d137901174ef7e15dbc2c9a2ec3ca1 + //if (newPath[0] !== ROOT) { newPath = [ROOT]; } return newPath; }; var onFileDrop = APP.onFileDrop = function (file, e) { diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 2752d52e7..27aade357 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -1600,7 +1600,16 @@ define([ // server Cryptpad.useTemplate({ href: data.template - }, Cryptget, function () { + }, Cryptget, function (err) { + if (err) { + // TODO: better messages in case of expired, deleted, etc.? + if (err === 'ERESTRICTED') { + sframeChan.event('EV_RESTRICTED_ERROR'); + } else { + sframeChan.query("EV_LOADING_ERROR", "DELETED"); + } + return; + } startRealtime(); cb(); }, cryptputCfg); @@ -1608,7 +1617,16 @@ define([ } // if we open a new code from a file if (Cryptpad.fromFileData) { - Cryptpad.useFile(Cryptget, function () { + Cryptpad.useFile(Cryptget, function (err) { + if (err) { + // TODO: better messages in case of expired, deleted, etc.? + if (err === 'ERESTRICTED') { + sframeChan.event('EV_RESTRICTED_ERROR'); + } else { + sframeChan.query("EV_LOADING_ERROR", "DELETED"); + } + return; + } startRealtime(); cb(); }, cryptputCfg);