Skip to content

Commit

Permalink
Improve error message when requests to server fail (#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch authored Feb 18, 2024
1 parent 0f8dabd commit 0da27ae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
11 changes: 8 additions & 3 deletions handlers/static/js/controllers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ function uploadFormData(url, formData, progressFn) {
}
});
xhr.addEventListener("error", () => {
reject("Failed to communicate with server: " + xhr.statusText);
reject(
"Failed to communicate with server" +
(xhr.statusText ? `: ${xhr.statusText}` : ".")
);
});
xhr.send(formData);
})
Expand Down Expand Up @@ -80,7 +83,8 @@ export async function editFile(id, filename, expiration, note) {
.catch((error) => {
if (error.message) {
return Promise.reject(
"Failed to communicate with server: " + error.message
"Failed to communicate with server" +
(error.message ? `: ${error.message}` : ".")
);
}
return Promise.reject(error);
Expand All @@ -103,7 +107,8 @@ export async function deleteFile(id) {
.catch((error) => {
if (error.message) {
return Promise.reject(
"Failed to communicate with server: " + error.message
"Failed to communicate with server" +
(error.message ? `: ${error.message}` : ".")
);
}
return Promise.reject(error);
Expand Down
6 changes: 4 additions & 2 deletions handlers/static/js/controllers/guestLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export async function guestLinkNew(
.catch((error) => {
if (error.message) {
return Promise.reject(
"Failed to communicate with server: " + error.message
"Failed to communicate with server" +
(error.message ? `: ${error.message}` : ".")
);
}
return Promise.reject(error);
Expand All @@ -50,7 +51,8 @@ export async function guestLinkDelete(id) {
.catch((error) => {
if (error.message) {
return Promise.reject(
"Failed to communicate with server: " + error.message
"Failed to communicate with server" +
(error.message ? `: ${error.message}` : ".")
);
}
return Promise.reject(error);
Expand Down
3 changes: 2 additions & 1 deletion handlers/static/js/controllers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export async function settingsPut(settings) {
.catch((error) => {
if (error.message) {
return Promise.reject(
"Failed to communicate with server: " + error.message
"Failed to communicate with server" +
(error.message ? `: ${error.message}` : ".")
);
}
return Promise.reject(error);
Expand Down

0 comments on commit 0da27ae

Please sign in to comment.