summaryrefslogtreecommitdiffhomepage
path: root/html
diff options
context:
space:
mode:
authorRoland Stigge <stigge@antcom.de>2018-01-10 20:49:03 +0100
committerRoland Stigge <stigge@antcom.de>2018-01-10 20:49:03 +0100
commit188a87d1a66f09dc7b224b89e6c1c16d77681423 (patch)
treea5e6c104af5af0548cb1e591b11b42f484c51b5a /html
parent97c8b7f21b8aeeda56f68deee8349f381d60eb96 (diff)
Handle errors from HTTP, separated out commands as classes
Diffstat (limited to 'html')
-rw-r--r--html/webbox.js49
1 files changed, 33 insertions, 16 deletions
diff --git a/html/webbox.js b/html/webbox.js
index 8612062..01738be 100644
--- a/html/webbox.js
+++ b/html/webbox.js
@@ -354,11 +354,14 @@ function createDir() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
- if (this.readyState != 4 || this.status != 200) {
+ if (this.readyState != 4) {
return;
}
-
- document.getElementById("dialog").innerHTML = xhr.responseText;
+ if (this.status != 200) {
+ document.getElementById("dialog").innerHTML = "HTTP error";
+ } else {
+ document.getElementById("dialog").innerHTML = xhr.responseText;
+ }
document.getElementById("okbutton").onclick = hideDialog;
document.getElementById("okbutton").focus();
loadContents(currentDir); // load new file list with new dir
@@ -396,18 +399,22 @@ function onUploadFile() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
- if (this.readyState != 4 || this.status != 200) {
+ if (this.readyState != 4) {
return;
}
showDialog();
var message = "";
- if (xhr.responseText == "OK") {
- message = "Upload successful.";
- loadContents(currentDir); // load new file list with uploaded file
+ if (this.status != 200) {
+ message = "HTTP error";
} else {
- message = "Error: " + xhr.responseText;
+ if (xhr.responseText == "OK") {
+ message = "Upload successful.";
+ loadContents(currentDir); // load new file list with uploaded file
+ } else {
+ message = "Error: " + xhr.responseText;
+ }
}
document.getElementById("dialog").innerHTML = message;
@@ -450,11 +457,14 @@ function deleteItems() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
- if (this.readyState != 4 || this.status != 200) {
+ if (this.readyState != 4) {
return;
}
-
- document.getElementById("dialog").innerHTML = xhr.responseText;
+ if (this.status != 200) {
+ document.getElementById("dialog").innerHTML = "HTTP error";
+ } else {
+ document.getElementById("dialog").innerHTML = xhr.responseText;
+ }
document.getElementById("okbutton").onclick = hideDialog;
loadContents(currentDir); // load new file list with deleted items
}
@@ -505,11 +515,15 @@ function move() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
- if (this.readyState != 4 || this.status != 200) {
+ if (this.readyState != 4) {
return;
}
+ if (this.status != 200) {
+ document.getElementById("dialog").innerHTML = "HTTP error";
+ } else {
+ document.getElementById("dialog").innerHTML = xhr.responseText;
+ }
- document.getElementById("dialog").innerHTML = xhr.responseText;
document.getElementById("okbutton").onclick = hideDialog;
document.getElementById("okbutton").focus();
loadContents(currentDir); // load new file list with deleted items
@@ -556,11 +570,14 @@ function info() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
- if (this.readyState != 4 || this.status != 200) {
+ if (this.readyState != 4) {
return;
}
-
- document.getElementById("dialog").innerHTML = xhr.responseText;
+ if (this.status != 200) {
+ document.getElementById("dialog").innerHTML = "HTTP error";
+ } else {
+ document.getElementById("dialog").innerHTML = xhr.responseText;
+ }
}
var parser = new DOMParser();