1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Update syncer to distinguish connection errors from other errors

We can automatically remove connection errors when things resume working
This commit is contained in:
Jeremy Ruston 2020-03-31 10:47:17 +01:00
parent 010483f705
commit 1154372a7b
2 changed files with 24 additions and 11 deletions

View File

@ -57,6 +57,12 @@ function Syncer(options) {
enable: this.logging,
saveHistory: true
});
// Make another logger for connection errors
this.loggerConnection = new $tw.utils.Logger("syncer" + ($tw.browser ? "-browser" : "") + ($tw.node ? "-server" : "") + (this.syncadaptor.name ? ("-" + this.syncadaptor.name) : "") + "-connection",{
colour: "cyan",
enable: this.logging
});
// Ask the syncadaptor to use the main logger
if(this.syncadaptor.setLoggerSaveBuffer) {
this.syncadaptor.setLoggerSaveBuffer(this.logger);
}
@ -136,9 +142,13 @@ function Syncer(options) {
/*
Show a generic network error alert
*/
Syncer.prototype.showErrorAlert = function() {
console.log($tw.language.getString("Error/NetworkErrorAlert"))
this.logger.alert($tw.language.getString("Error/NetworkErrorAlert"));
Syncer.prototype.displayError = function(msg,err) {
if(err === ($tw.language.getString("Error/XMLHttpRequest") + ": 0")) {
this.loggerConnection.alert($tw.language.getString("Error/NetworkErrorAlert"));
this.logger.log(msg + ":",err);
} else {
this.logger.alert(msg + ":",err);
}
};
/*
@ -220,7 +230,7 @@ Syncer.prototype.updateDirtyStatus = function() {
var dirty = this.isDirty();
$tw.utils.toggleClass(document.body,"tc-dirty",dirty);
if(!dirty) {
this.logger.clearAlerts();
this.loggerConnection.clearAlerts();
}
}
};
@ -292,8 +302,7 @@ Syncer.prototype.syncFromServer = function() {
this.syncadaptor.getUpdatedTiddlers(self,function(err,updates) {
triggerNextSync();
if(err) {
self.showErrorAlert();
self.logger.log($tw.language.getString("Error/RetrievingSkinny") + ":",err);
self.displayError($tw.language.getString("Error/RetrievingSkinny"),err);
return;
}
if(updates) {
@ -317,8 +326,7 @@ Syncer.prototype.syncFromServer = function() {
triggerNextSync();
// Check for errors
if(err) {
self.showErrorAlert();
self.logger.log($tw.language.getString("Error/RetrievingSkinny") + ":",err);
self.displayError($tw.language.getString("Error/RetrievingSkinny"),err);
return;
}
// Keep track of which tiddlers we already know about have been reported this time
@ -468,8 +476,7 @@ Syncer.prototype.processTaskQueue = function() {
task.run(function(err) {
self.numTasksInProgress -= 1;
if(err) {
self.showErrorAlert();
self.logger.log("Sync error while processing " + task.type + " of '" + task.title + "':\n" + err);
self.displayError("Sync error while processing " + task.type + " of '" + task.title + "'",err);
self.updateDirtyStatus();
self.triggerTimeout(self.errorRetryInterval);
} else {

View File

@ -27,7 +27,13 @@ Nothing should be exported if the adaptor detects that it isn't capable of opera
! Adaptor Module Methods
Adaptor modules must handle the following methods.
Adaptor modules must handle the methods described below.
!!! Error Handling
The syncadaptor must invoke the provided callback with the ''err'' parameter containing a string describing the error.
The syncer has special handling for connection errors. For backwards compatibilty reasons, the syncer identifies connection errors as the string comprised of the content of the tiddler $:/language/Error/XMLHttpRequest with the string ": 0" appended to the end. For example, in English, the string is "XMLHttpRequest error code: 0" and in Brazilian Portuguese it is "Código de erro XMLHttpRequest: 0".
!! `Constructor(options)`