Skip to content

Commit fdd7f78

Browse files
authored
Merge pull request #2031 from maxberger/master
Improve error messaging when server is not reachable
2 parents fee902f + 49eeccd commit fdd7f78

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

radicale/web/internal_data/js/api/api.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import { COLOR_RE, ROOT_PATH, SERVER } from "../constants.js";
2323
import { Collection, CollectionType } from "../models/collection.js";
2424
import { escape_xml } from "../utils/misc.js";
25-
25+
import { to_error_message } from "./common.js";
2626

2727
/**
2828
* Find the principal collection.
@@ -56,7 +56,7 @@ export function get_principal(user, password, callback) {
5656
callback(null, "Internal error");
5757
}
5858
} else {
59-
callback(null, request.status + " " + request.statusText);
59+
callback(null, to_error_message(request));
6060
}
6161
};
6262
request.send('<?xml version="1.0" encoding="utf-8" ?>' +
@@ -163,7 +163,7 @@ export function get_collections(user, password, collection, callback) {
163163
});
164164
callback(collections, null);
165165
} else {
166-
callback(null, request.status + " " + request.statusText);
166+
callback(null, to_error_message(request));
167167
}
168168
};
169169
request.send('<?xml version="1.0" encoding="utf-8" ?>' +
@@ -210,7 +210,7 @@ export function upload_collection(user, password, collection_href, file, callbac
210210
if (200 <= request.status && request.status < 300) {
211211
callback(null);
212212
} else {
213-
callback(request.status + " " + request.statusText);
213+
callback(to_error_message(request));
214214
}
215215
};
216216
request.setRequestHeader("If-None-Match", "*");
@@ -235,7 +235,7 @@ export function delete_collection(user, password, collection, callback) {
235235
if (200 <= request.status && request.status < 300) {
236236
callback(null);
237237
} else {
238-
callback(request.status + " " + request.statusText);
238+
callback(to_error_message(request));
239239
}
240240
};
241241
request.send();
@@ -260,7 +260,7 @@ function create_edit_collection(user, password, collection, create, callback) {
260260
if (200 <= request.status && request.status < 300) {
261261
callback(null);
262262
} else {
263-
callback(request.status + " " + request.statusText);
263+
callback(to_error_message(request));
264264
}
265265
};
266266
let displayname = escape_xml(collection.displayname);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* This file is part of Radicale Server - Calendar Server
3+
* Copyright © 2017-2024 Unrud <unrud@outlook.com>
4+
* Copyright © 2023-2024 Matthew Hana <matthew.hana@gmail.com>
5+
* Copyright © 2024-2025 Peter Bieringer <pb@bieringer.de>
6+
* Copyright © 2026-2026 Max Berger <max@berger.name>
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
/**
23+
* @param {XMLHttpRequest} request
24+
* @returns {string}
25+
*/
26+
export function to_error_message(request) {
27+
let have_status_text = (request.statusText != null && request.statusText != undefined && request.statusText != '')
28+
if ((request.status == 0) && (!have_status_text)) {
29+
return "Could not connect to server";
30+
}
31+
32+
return request.status + " " + request.statusText;
33+
}

radicale/web/internal_data/js/api/sharing.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import { ROOT_PATH, SERVER } from "../constants.js";
2020
import { CollectionType } from "../models/collection.js";
21+
import { to_error_message } from "./common.js";
2122

2223
/**
2324
* @typedef {Object} SharingFeatures
@@ -79,9 +80,9 @@ function call_sharing_api(
7980
}
8081
} else {
8182
if (on_error) {
82-
on_error(request.status + " " + request.statusText);
83+
on_error(to_error_message(request));
8384
} else {
84-
console.error(request.status + " " + request.statusText);
85+
console.error(to_error_message(request));
8586
}
8687
}
8788
};

0 commit comments

Comments
 (0)