diff --git a/web_interface/templates/v3/partials/raw_json.html b/web_interface/templates/v3/partials/raw_json.html
index fa2cb9c84..b726fd465 100644
--- a/web_interface/templates/v3/partials/raw_json.html
+++ b/web_interface/templates/v3/partials/raw_json.html
@@ -218,19 +218,28 @@
Security Notice
},
body: JSON.stringify(config)
})
- .then(response => {
- // Check if response is OK before parsing JSON
+ .then(async response => {
+ // Store status and statusText before parsing
+ const status = response.status;
+ const statusText = response.statusText;
+
+ // Try to parse JSON response
+ let data;
+ try {
+ data = await response.json();
+ } catch (parseError) {
+ // If JSON parsing fails, throw generic HTTP error
+ throw new Error(`HTTP ${status}: ${statusText}`);
+ }
+
+ // Handle non-OK responses
if (!response.ok) {
- // Try to parse error response as JSON, fallback to status text
- return response.json().then(data => {
- throw new Error(data.message || response.statusText);
- }).catch(() => {
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
- });
+ // Extract specific error message from API response if available
+ const errorMessage = data.message || data.status || statusText;
+ throw new Error(errorMessage);
}
- return response.json();
- })
- .then(data => {
+
+ // Handle successful responses
if (data.status === 'success') {
showNotification('config.json saved successfully!', 'success');
} else {
@@ -238,6 +247,7 @@ Security Notice
}
})
.catch(error => {
+ // Preserve the error message that was intentionally thrown
showNotification('Error saving config.json: ' + (error.message || 'An error occurred'), 'error');
});
} catch (e) {
@@ -265,19 +275,28 @@ Security Notice
},
body: JSON.stringify(config)
})
- .then(response => {
- // Check if response is OK before parsing JSON
+ .then(async response => {
+ // Store status and statusText before parsing
+ const status = response.status;
+ const statusText = response.statusText;
+
+ // Try to parse JSON response
+ let data;
+ try {
+ data = await response.json();
+ } catch (parseError) {
+ // If JSON parsing fails, throw generic HTTP error
+ throw new Error(`HTTP ${status}: ${statusText}`);
+ }
+
+ // Handle non-OK responses
if (!response.ok) {
- // Try to parse error response as JSON, fallback to status text
- return response.json().then(data => {
- throw new Error(data.message || response.statusText);
- }).catch(() => {
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
- });
+ // Extract specific error message from API response if available
+ const errorMessage = data.message || data.status || statusText;
+ throw new Error(errorMessage);
}
- return response.json();
- })
- .then(data => {
+
+ // Handle successful responses
if (data.status === 'success') {
showNotification('config_secrets.json saved successfully!', 'success');
} else {
@@ -285,6 +304,7 @@ Security Notice
}
})
.catch(error => {
+ // Preserve the error message that was intentionally thrown
showNotification('Error saving config_secrets.json: ' + (error.message || 'An error occurred'), 'error');
});
} catch (e) {