amine_dubs
commited on
Commit
·
5d570c5
1
Parent(s):
47cd112
- static/script.js +26 -1
static/script.js
CHANGED
@@ -12,7 +12,30 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
12 |
|
13 |
// Helper function to display errors
|
14 |
function displayError(message) {
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
errorMessageDiv.style.display = 'block';
|
17 |
// Hide result boxes on error
|
18 |
textResultBox.style.display = 'none';
|
@@ -78,6 +101,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
78 |
|
79 |
} catch (error) {
|
80 |
console.error('Text translation error:', error);
|
|
|
81 |
displayError(error.message || 'An unexpected error occurred during text translation.');
|
82 |
} finally {
|
83 |
button.disabled = false;
|
@@ -130,6 +154,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
130 |
|
131 |
} catch (error) {
|
132 |
console.error('Document translation error:', error);
|
|
|
133 |
displayError(error.message || 'An unexpected error occurred during document translation.');
|
134 |
} finally {
|
135 |
button.disabled = false;
|
|
|
12 |
|
13 |
// Helper function to display errors
|
14 |
function displayError(message) {
|
15 |
+
let errorText = 'Error: ';
|
16 |
+
|
17 |
+
if (message === undefined || message === null) {
|
18 |
+
errorText += 'Unknown error occurred';
|
19 |
+
} else if (typeof message === 'object') {
|
20 |
+
// Better error object handling
|
21 |
+
if (message.message) {
|
22 |
+
errorText += message.message;
|
23 |
+
} else if (message.detail) {
|
24 |
+
errorText += message.detail;
|
25 |
+
} else if (message.error) {
|
26 |
+
errorText += message.error;
|
27 |
+
} else {
|
28 |
+
try {
|
29 |
+
errorText += JSON.stringify(message);
|
30 |
+
} catch (e) {
|
31 |
+
errorText += 'Unable to display error details';
|
32 |
+
}
|
33 |
+
}
|
34 |
+
} else {
|
35 |
+
errorText += message;
|
36 |
+
}
|
37 |
+
|
38 |
+
errorMessageDiv.textContent = errorText;
|
39 |
errorMessageDiv.style.display = 'block';
|
40 |
// Hide result boxes on error
|
41 |
textResultBox.style.display = 'none';
|
|
|
101 |
|
102 |
} catch (error) {
|
103 |
console.error('Text translation error:', error);
|
104 |
+
// Always pass error.message instead of the error object
|
105 |
displayError(error.message || 'An unexpected error occurred during text translation.');
|
106 |
} finally {
|
107 |
button.disabled = false;
|
|
|
154 |
|
155 |
} catch (error) {
|
156 |
console.error('Document translation error:', error);
|
157 |
+
// Always pass error.message instead of the error object
|
158 |
displayError(error.message || 'An unexpected error occurred during document translation.');
|
159 |
} finally {
|
160 |
button.disabled = false;
|