mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-30 05:19:57 +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:
parent
010483f705
commit
1154372a7b
@ -57,6 +57,12 @@ function Syncer(options) {
|
|||||||
enable: this.logging,
|
enable: this.logging,
|
||||||
saveHistory: true
|
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) {
|
if(this.syncadaptor.setLoggerSaveBuffer) {
|
||||||
this.syncadaptor.setLoggerSaveBuffer(this.logger);
|
this.syncadaptor.setLoggerSaveBuffer(this.logger);
|
||||||
}
|
}
|
||||||
@ -136,9 +142,13 @@ function Syncer(options) {
|
|||||||
/*
|
/*
|
||||||
Show a generic network error alert
|
Show a generic network error alert
|
||||||
*/
|
*/
|
||||||
Syncer.prototype.showErrorAlert = function() {
|
Syncer.prototype.displayError = function(msg,err) {
|
||||||
console.log($tw.language.getString("Error/NetworkErrorAlert"))
|
if(err === ($tw.language.getString("Error/XMLHttpRequest") + ": 0")) {
|
||||||
this.logger.alert($tw.language.getString("Error/NetworkErrorAlert"));
|
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();
|
var dirty = this.isDirty();
|
||||||
$tw.utils.toggleClass(document.body,"tc-dirty",dirty);
|
$tw.utils.toggleClass(document.body,"tc-dirty",dirty);
|
||||||
if(!dirty) {
|
if(!dirty) {
|
||||||
this.logger.clearAlerts();
|
this.loggerConnection.clearAlerts();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -292,8 +302,7 @@ Syncer.prototype.syncFromServer = function() {
|
|||||||
this.syncadaptor.getUpdatedTiddlers(self,function(err,updates) {
|
this.syncadaptor.getUpdatedTiddlers(self,function(err,updates) {
|
||||||
triggerNextSync();
|
triggerNextSync();
|
||||||
if(err) {
|
if(err) {
|
||||||
self.showErrorAlert();
|
self.displayError($tw.language.getString("Error/RetrievingSkinny"),err);
|
||||||
self.logger.log($tw.language.getString("Error/RetrievingSkinny") + ":",err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(updates) {
|
if(updates) {
|
||||||
@ -317,8 +326,7 @@ Syncer.prototype.syncFromServer = function() {
|
|||||||
triggerNextSync();
|
triggerNextSync();
|
||||||
// Check for errors
|
// Check for errors
|
||||||
if(err) {
|
if(err) {
|
||||||
self.showErrorAlert();
|
self.displayError($tw.language.getString("Error/RetrievingSkinny"),err);
|
||||||
self.logger.log($tw.language.getString("Error/RetrievingSkinny") + ":",err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Keep track of which tiddlers we already know about have been reported this time
|
// 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) {
|
task.run(function(err) {
|
||||||
self.numTasksInProgress -= 1;
|
self.numTasksInProgress -= 1;
|
||||||
if(err) {
|
if(err) {
|
||||||
self.showErrorAlert();
|
self.displayError("Sync error while processing " + task.type + " of '" + task.title + "'",err);
|
||||||
self.logger.log("Sync error while processing " + task.type + " of '" + task.title + "':\n" + err);
|
|
||||||
self.updateDirtyStatus();
|
self.updateDirtyStatus();
|
||||||
self.triggerTimeout(self.errorRetryInterval);
|
self.triggerTimeout(self.errorRetryInterval);
|
||||||
} else {
|
} else {
|
||||||
|
@ -27,7 +27,13 @@ Nothing should be exported if the adaptor detects that it isn't capable of opera
|
|||||||
|
|
||||||
! Adaptor Module Methods
|
! 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)`
|
!! `Constructor(options)`
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user