serialize localForage errors and add a safety net
parent
662629185d
commit
7ddeacc629
|
@ -32,7 +32,7 @@ define([
|
|||
if (!allowed) { return void cb('NOCACHE'); }
|
||||
cache.getItem(id, function (err, obj) {
|
||||
if (err || !obj || !obj.c) {
|
||||
return void cb(err || 'EINVAL');
|
||||
return void cb(Util.serializeError(err || 'EINVAL'));
|
||||
}
|
||||
cb(null, obj.c);
|
||||
obj.t = +new Date();
|
||||
|
@ -50,7 +50,7 @@ define([
|
|||
c: u8,
|
||||
t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set)
|
||||
}, function (err) {
|
||||
cb(err);
|
||||
cb(Util.serializeError(err));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -64,7 +64,7 @@ define([
|
|||
if (!allowed) { return void cb('NOCACHE'); }
|
||||
cache.getItem(id, function (err, obj) {
|
||||
if (err || !obj || !Array.isArray(obj.c)) {
|
||||
return void cb(err || 'EINVAL');
|
||||
return void cb(Util.serializeError(err || 'EINVAL'));
|
||||
}
|
||||
cb(null, obj);
|
||||
obj.t = +new Date();
|
||||
|
@ -108,7 +108,7 @@ define([
|
|||
c: val,
|
||||
t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set)
|
||||
}, function (err) {
|
||||
if (err) { onError(err); }
|
||||
if (err) { onError(Util.serializeError(err)); }
|
||||
});
|
||||
|
||||
}, 50);
|
||||
|
|
|
@ -157,7 +157,24 @@ define([
|
|||
var msgEv = _Util.mkEvent();
|
||||
var iframe = $('#sbox-iframe')[0].contentWindow;
|
||||
var postMsg = function (data) {
|
||||
iframe.postMessage(data, '*');
|
||||
try {
|
||||
iframe.postMessage(data, '*');
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
console.error(data);
|
||||
if (data && data.error && data.error instanceof Error) {
|
||||
data.error = Util.serializeError(data.error);
|
||||
try {
|
||||
iframe.postMessage(data, '*');
|
||||
} catch (err2) {
|
||||
// XXX
|
||||
console.error("impossible serialization");
|
||||
throw err2;
|
||||
}
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
var whenReady = waitFor(function (msg) {
|
||||
if (msg.source !== iframe) { return; }
|
||||
|
|
Loading…
Reference in New Issue