Skip to content

Commit cbfc9ca

Browse files
committed
Show fancier error message dialogs for Imgur upload failures
1 parent 23fce99 commit cbfc9ca

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/imgur.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// @ts-check
22
/* global localize */
33
import { $DialogWindow } from "./$ToolWindow.js";
4+
import { show_error_message } from "./functions.js";
45
// import { localize } from "./app-localization.js";
5-
import { E } from "./helpers.js";
6+
import { E, is_discord_embed } from "./helpers.js";
67

78
let $imgur_window;
89

@@ -119,7 +120,9 @@ function show_imgur_uploader(blob) {
119120
if (!response) return;
120121

121122
if (!response.success) {
122-
$imgur_status.text("Failed to upload image :(");
123+
//$imgur_status.text("Failed to upload image :(");
124+
$imgur_window.close();
125+
show_error_message("Failed to upload image.", req.responseText);
123126
return;
124127
}
125128
const url = response.data.link;
@@ -174,8 +177,27 @@ function show_imgur_uploader(blob) {
174177
$imgur_window.close();
175178
}).focus();
176179
} else if (req.readyState == 4) {
177-
$progress.add($progress_percent).remove();
178-
$imgur_status.text("Error uploading image :(");
180+
//$progress.add($progress_percent).remove();
181+
//$imgur_status.text("Error uploading image :(");
182+
$imgur_window.close();
183+
if (is_discord_embed) {
184+
// closest localized string: "An unsupported operation was attempted."
185+
show_error_message("Uploading to Imgur is not currently supported in the Discord Activity.");
186+
} else {
187+
let response;
188+
try {
189+
response = JSON.parse(req.responseText);
190+
} catch (error) {
191+
// Prefer to show error about failing to upload,
192+
// rather than it not being JSON.
193+
// Full response can be shown in the expandible details.
194+
}
195+
if (response && response.data && response.data.error) {
196+
show_error_message(`Failed to upload image.\n\n${response.data.error}`, req.responseText);
197+
} else {
198+
show_error_message(`Failed to upload image. HTTP ${req.status}`, req.responseText);
199+
}
200+
}
179201
}
180202
});
181203

0 commit comments

Comments
 (0)