|
1 | 1 | // @ts-check |
2 | 2 | /* global localize */ |
3 | 3 | import { $DialogWindow } from "./$ToolWindow.js"; |
| 4 | +import { show_error_message } from "./functions.js"; |
4 | 5 | // import { localize } from "./app-localization.js"; |
5 | | -import { E } from "./helpers.js"; |
| 6 | +import { E, is_discord_embed } from "./helpers.js"; |
6 | 7 |
|
7 | 8 | let $imgur_window; |
8 | 9 |
|
@@ -119,7 +120,9 @@ function show_imgur_uploader(blob) { |
119 | 120 | if (!response) return; |
120 | 121 |
|
121 | 122 | 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); |
123 | 126 | return; |
124 | 127 | } |
125 | 128 | const url = response.data.link; |
@@ -174,8 +177,27 @@ function show_imgur_uploader(blob) { |
174 | 177 | $imgur_window.close(); |
175 | 178 | }).focus(); |
176 | 179 | } 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 | + } |
179 | 201 | } |
180 | 202 | }); |
181 | 203 |
|
|
0 commit comments