Remove errors from the cache when they are shown to the user (#1392)
There's really no reason to retry encryption errors again if they've already been made user-visible in a conversation. Also, refactor e->error in background.js onError(), since both e and ev in this method made it too easy to make a mistake.
This commit is contained in:
parent
84fd605ad3
commit
9fb079253c
3 changed files with 17 additions and 8 deletions
|
@ -302,18 +302,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function onError(ev) {
|
function onError(ev) {
|
||||||
var e = ev.error;
|
var error = ev.error;
|
||||||
console.log(e);
|
console.log(error);
|
||||||
console.log(e.stack);
|
console.log(error.stack);
|
||||||
|
|
||||||
if (e.name === 'HTTPError' && (e.code == 401 || e.code == 403)) {
|
if (error.name === 'HTTPError' && (error.code == 401 || error.code == 403)) {
|
||||||
Whisper.Registration.remove();
|
Whisper.Registration.remove();
|
||||||
Whisper.events.trigger('unauthorized');
|
Whisper.events.trigger('unauthorized');
|
||||||
extension.install();
|
extension.install();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.name === 'HTTPError' && e.code == -1) {
|
if (error.name === 'HTTPError' && error.code == -1) {
|
||||||
// Failed to connect to server
|
// Failed to connect to server
|
||||||
if (navigator.onLine) {
|
if (navigator.onLine) {
|
||||||
console.log('retrying in 1 minute');
|
console.log('retrying in 1 minute');
|
||||||
|
@ -329,7 +329,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ev.proto) {
|
if (ev.proto) {
|
||||||
if (e.name === 'MessageCounterError') {
|
if (error.name === 'MessageCounterError') {
|
||||||
|
if (ev.confirm) {
|
||||||
|
ev.confirm();
|
||||||
|
}
|
||||||
// Ignore this message. It is likely a duplicate delivery
|
// Ignore this message. It is likely a duplicate delivery
|
||||||
// because the server lost our ack the first time.
|
// because the server lost our ack the first time.
|
||||||
return;
|
return;
|
||||||
|
@ -337,7 +340,7 @@
|
||||||
var envelope = ev.proto;
|
var envelope = ev.proto;
|
||||||
var message = initIncomingMessage(envelope);
|
var message = initIncomingMessage(envelope);
|
||||||
|
|
||||||
return message.saveErrors(e).then(function() {
|
return message.saveErrors(error).then(function() {
|
||||||
var id = message.get('conversationId');
|
var id = message.get('conversationId');
|
||||||
return ConversationController.findOrCreateById(id, 'private').then(function(conversation) {
|
return ConversationController.findOrCreateById(id, 'private').then(function(conversation) {
|
||||||
conversation.set({
|
conversation.set({
|
||||||
|
@ -356,6 +359,10 @@
|
||||||
conversation.notify(message);
|
conversation.notify(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ev.confirm) {
|
||||||
|
ev.confirm();
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
conversation.save().then(resolve, reject);
|
conversation.save().then(resolve, reject);
|
||||||
});
|
});
|
||||||
|
@ -363,7 +370,7 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
throw e;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onReadReceipt(ev) {
|
function onReadReceipt(ev) {
|
||||||
|
|
|
@ -38631,6 +38631,7 @@ MessageReceiver.prototype.extend({
|
||||||
var ev = new Event('error');
|
var ev = new Event('error');
|
||||||
ev.error = error;
|
ev.error = error;
|
||||||
ev.proto = envelope;
|
ev.proto = envelope;
|
||||||
|
ev.confirm = this.removeFromCache.bind(this, envelope);
|
||||||
|
|
||||||
var returnError = function() {
|
var returnError = function() {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
|
|
|
@ -380,6 +380,7 @@ MessageReceiver.prototype.extend({
|
||||||
var ev = new Event('error');
|
var ev = new Event('error');
|
||||||
ev.error = error;
|
ev.error = error;
|
||||||
ev.proto = envelope;
|
ev.proto = envelope;
|
||||||
|
ev.confirm = this.removeFromCache.bind(this, envelope);
|
||||||
|
|
||||||
var returnError = function() {
|
var returnError = function() {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
|
|
Loading…
Reference in a new issue