mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-23 07:26:54 +00:00
Better error trapping for WebDAV saver
Without these checks we get a startup crash when using TiddlyWiki in client-server configuration.
This commit is contained in:
parent
f0ff1f993e
commit
91b341e8e0
@ -29,16 +29,20 @@ var PutSaver = function(wiki) {
|
|||||||
type: "OPTIONS",
|
type: "OPTIONS",
|
||||||
callback: function(err, data, xhr) {
|
callback: function(err, data, xhr) {
|
||||||
// Check DAV header http://www.webdav.org/specs/rfc2518.html#rfc.section.9.1
|
// Check DAV header http://www.webdav.org/specs/rfc2518.html#rfc.section.9.1
|
||||||
|
if(!err) {
|
||||||
self.serverAcceptsPuts = xhr.status === 200 && !!xhr.getResponseHeader("dav");
|
self.serverAcceptsPuts = xhr.status === 200 && !!xhr.getResponseHeader("dav");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// Retrieve ETag if available
|
// Retrieve ETag if available
|
||||||
$tw.utils.httpRequest({
|
$tw.utils.httpRequest({
|
||||||
url: uri,
|
url: uri,
|
||||||
type: "HEAD",
|
type: "HEAD",
|
||||||
callback: function(err, data, xhr) {
|
callback: function(err, data, xhr) {
|
||||||
|
if(!err) {
|
||||||
self.etag = xhr.getResponseHeader("ETag");
|
self.etag = xhr.getResponseHeader("ETag");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -50,12 +54,12 @@ PutSaver.prototype.uri = function() {
|
|||||||
// Prompt: Do you want to save over this? Y/N
|
// Prompt: Do you want to save over this? Y/N
|
||||||
// Merging would be ideal, and may be possible using future generic merge flow
|
// Merging would be ideal, and may be possible using future generic merge flow
|
||||||
PutSaver.prototype.save = function(text, method, callback) {
|
PutSaver.prototype.save = function(text, method, callback) {
|
||||||
if (!this.serverAcceptsPuts) {
|
if(!this.serverAcceptsPuts) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var self = this;
|
var self = this;
|
||||||
var headers = { "Content-Type": "text/html;charset=UTF-8" };
|
var headers = { "Content-Type": "text/html;charset=UTF-8" };
|
||||||
if (this.etag) {
|
if(this.etag) {
|
||||||
headers["If-Match"] = this.etag;
|
headers["If-Match"] = this.etag;
|
||||||
}
|
}
|
||||||
$tw.utils.httpRequest({
|
$tw.utils.httpRequest({
|
||||||
@ -64,15 +68,15 @@ PutSaver.prototype.save = function(text, method, callback) {
|
|||||||
headers: headers,
|
headers: headers,
|
||||||
data: text,
|
data: text,
|
||||||
callback: function(err, data, xhr) {
|
callback: function(err, data, xhr) {
|
||||||
if (xhr.status === 200 || xhr.status === 201) {
|
if(err) {
|
||||||
|
callback(err);
|
||||||
|
} if(xhr.status === 200 || xhr.status === 201) {
|
||||||
self.etag = xhr.getResponseHeader("ETag");
|
self.etag = xhr.getResponseHeader("ETag");
|
||||||
callback(null); // success
|
callback(null); // success
|
||||||
}
|
} else if(xhr.status === 412) { // edit conflict
|
||||||
else if (xhr.status === 412) { // edit conflict
|
|
||||||
var message = $tw.language.getString("Error/EditConflict");
|
var message = $tw.language.getString("Error/EditConflict");
|
||||||
callback(message);
|
callback(message);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
callback(xhr.responseText); // fail
|
callback(xhr.responseText); // fail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user