diff --git a/radicale/web/internal_data/js/api/api.js b/radicale/web/internal_data/js/api/api.js index 4754d61f..d061523f 100644 --- a/radicale/web/internal_data/js/api/api.js +++ b/radicale/web/internal_data/js/api/api.js @@ -22,7 +22,7 @@ import { COLOR_RE, ROOT_PATH, SERVER } from "../constants.js"; import { Collection, CollectionType } from "../models/collection.js"; import { escape_xml } from "../utils/misc.js"; - +import { to_error_message } from "./common.js"; /** * Find the principal collection. @@ -56,7 +56,7 @@ export function get_principal(user, password, callback) { callback(null, "Internal error"); } } else { - callback(null, request.status + " " + request.statusText); + callback(null, to_error_message(request)); } }; request.send('' + @@ -163,7 +163,7 @@ export function get_collections(user, password, collection, callback) { }); callback(collections, null); } else { - callback(null, request.status + " " + request.statusText); + callback(null, to_error_message(request)); } }; request.send('' + @@ -210,7 +210,7 @@ export function upload_collection(user, password, collection_href, file, callbac if (200 <= request.status && request.status < 300) { callback(null); } else { - callback(request.status + " " + request.statusText); + callback(to_error_message(request)); } }; request.setRequestHeader("If-None-Match", "*"); @@ -235,7 +235,7 @@ export function delete_collection(user, password, collection, callback) { if (200 <= request.status && request.status < 300) { callback(null); } else { - callback(request.status + " " + request.statusText); + callback(to_error_message(request)); } }; request.send(); @@ -260,7 +260,7 @@ function create_edit_collection(user, password, collection, create, callback) { if (200 <= request.status && request.status < 300) { callback(null); } else { - callback(request.status + " " + request.statusText); + callback(to_error_message(request)); } }; let displayname = escape_xml(collection.displayname); diff --git a/radicale/web/internal_data/js/api/common.js b/radicale/web/internal_data/js/api/common.js new file mode 100644 index 00000000..c69637e9 --- /dev/null +++ b/radicale/web/internal_data/js/api/common.js @@ -0,0 +1,33 @@ +/** + * This file is part of Radicale Server - Calendar Server + * Copyright © 2017-2024 Unrud + * Copyright © 2023-2024 Matthew Hana + * Copyright © 2024-2025 Peter Bieringer + * Copyright © 2026-2026 Max Berger + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @param {XMLHttpRequest} request + * @returns {string} + */ +export function to_error_message(request) { + let have_status_text = (request.statusText != null && request.statusText != undefined && request.statusText != '') + if ((request.status == 0) && (!have_status_text)) { + return "Could not connect to server"; + } + + return request.status + " " + request.statusText; +} \ No newline at end of file diff --git a/radicale/web/internal_data/js/api/sharing.js b/radicale/web/internal_data/js/api/sharing.js index be118039..1d3feedc 100644 --- a/radicale/web/internal_data/js/api/sharing.js +++ b/radicale/web/internal_data/js/api/sharing.js @@ -18,6 +18,7 @@ import { ROOT_PATH, SERVER } from "../constants.js"; import { CollectionType } from "../models/collection.js"; +import { to_error_message } from "./common.js"; /** * @typedef {Object} SharingFeatures @@ -79,9 +80,9 @@ function call_sharing_api( } } else { if (on_error) { - on_error(request.status + " " + request.statusText); + on_error(to_error_message(request)); } else { - console.error(request.status + " " + request.statusText); + console.error(to_error_message(request)); } } };