Skip to content

Commit c7fbbc7

Browse files
committed
Allow to provide additional details in error dialogue
1 parent fa6fa14 commit c7fbbc7

File tree

4 files changed

+60
-15
lines changed

4 files changed

+60
-15
lines changed

assets/webconfig/i18n/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,9 @@
12321232
"wiz_yeelight_desc2": "Now choose which lamps should be added. The position assigns the lamp to a specific position on your \"picture\". Disabled lamps won't be added. To identify single lamps press the button on the right.",
12331233
"wiz_yeelight_intro1": "This wizard configures Hyperion for the Yeelight system. Features are the Yeelights' auto detection, setting each light to a specific position on your picture or disable it and tune the Hyperion settings automatically! So in short: All you need are some clicks and you are done!",
12341234
"wiz_yeelight_title": "Yeelight Wizard",
1235-
"wiz_yeelight_unsupported": "Unsupported"
1235+
"wiz_yeelight_unsupported": "Unsupported",
1236+
"ws_error_occured": "WebSocket error occured",
1237+
"ws_not_supported": "Websocket is not supported by your browser",
1238+
"ws_processing_exception": "Exception during Websocket message processing"
12361239
}
12371240

assets/webconfig/js/content_index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,11 @@ $(document).ready(function () {
242242
$(window.hyperion).on("error", function (event) {
243243
//If we are getting an error "No Authorization" back with a set loginToken we will forward to new Login (Token is expired.
244244
//e.g.: hyperiond was started new in the meantime)
245-
if (event.reason == "No Authorization" && getStorage("loginToken")) {
245+
if (event.reason.message == "No Authorization" && getStorage("loginToken")) {
246246
removeStorage("loginToken");
247247
requestRequiresDefaultPasswortChange();
248248
} else {
249-
showInfoDialog("error", "Error", event.reason);
249+
showInfoDialog("error", "", event.reason.message, event.reason.details);
250250
}
251251
});
252252

assets/webconfig/js/hyperion.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,27 +126,50 @@ function initWebSocket() {
126126
if (error == "Service Unavailable") {
127127
window.location.reload();
128128
} else {
129-
$(window.hyperion).trigger({ type: "error", reason: error });
129+
const errorData = Array.isArray(response.errorData) ? response.errorData : [];
130+
console.log("[window.websocket::onmessage] ", error, ", Description:", errorData);
131+
$(window.hyperion).trigger({
132+
type: "error",
133+
reason: {
134+
message: error,
135+
details: errorData.map((item) => item.description || "")
136+
}
137+
});
130138
}
131-
let errorData = response.hasOwnProperty("errorData") ? response.errorData : "";
132-
console.log("[window.websocket::onmessage] ", error, ", Description:", errorData);
133139
}
134140
}
135141
catch (exception_error) {
136-
$(window.hyperion).trigger({ type: "error", reason: exception_error });
137-
console.log("[window.websocket::onmessage] ", exception_error)
142+
console.log("[window.websocket::onmessage] ", exception_error);
143+
$(window.hyperion).trigger({
144+
type: "error",
145+
reason: {
146+
message: $.i18n("ws_processing_exception") + ": " + exception_error.message,
147+
details: [exception_error.stack]
148+
}
149+
});
138150
}
139151
};
140152

141153
window.websocket.onerror = function (error) {
142-
$(window.hyperion).trigger({ type: "error", reason: error });
143-
console.log("[window.websocket::onerror] ", error)
154+
console.log("[window.websocket::onerror] ", error);
155+
$(window.hyperion).trigger({
156+
type: "error",
157+
reason: {
158+
message: $.i18n("ws_error_occured"),
159+
details: [error]
160+
}
161+
});
144162
};
145163
}
146164
}
147165
else {
148-
$(window.hyperion).trigger("error");
149-
alert("Websocket is not supported by your browser");
166+
$(window.hyperion).trigger({
167+
type: "error",
168+
reason: {
169+
message: $.i18n("ws_not_supported"),
170+
details: []
171+
}
172+
});
150173
}
151174
}
152175

assets/webconfig/js/ui_utils.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ function setClassByBool(obj, enable, class1, class2) {
307307
}
308308
}
309309

310-
function showInfoDialog(type, header, message) {
310+
function showInfoDialog(type, header = "", message = "", details = []) {
311311
if (type == "success") {
312312
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-check modal-icon-check">');
313313
if (header == "")
@@ -321,9 +321,10 @@ function showInfoDialog(type, header, message) {
321321
$('#id_footer').html('<button type="button" class="btn btn-warning" data-dismiss="modal">' + $.i18n('general_btn_ok') + '</button>');
322322
}
323323
else if (type == "error") {
324-
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-warning modal-icon-error">');
325-
if (header == "")
324+
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-warning modal-icon-error"></i>');
325+
if (header == "") {
326326
$('#id_body').append('<h4 style="font-weight:bold;text-transform:uppercase;">' + $.i18n('infoDialog_general_error_title') + '</h4>');
327+
}
327328
$('#id_footer').html('<button type="button" class="btn btn-danger" data-dismiss-modal="#modal_dialog">' + $.i18n('general_btn_ok') + '</button>');
328329
}
329330
else if (type == "select") {
@@ -394,6 +395,24 @@ function showInfoDialog(type, header, message) {
394395
if (type == "select" || type == "iswitch")
395396
$('#id_body').append('<select id="id_select" class="form-control" style="margin-top:10px;width:auto;"></select>');
396397

398+
// Append details if available
399+
if (Array.isArray(details) && details.length > 0) {
400+
401+
// Create a container div for additional details with proper styles
402+
const detailsContent = $('<div></div>').css({
403+
'text-align': 'left',
404+
'white-space': 'pre-wrap', // Ensures newlines are respected
405+
'word-wrap': 'break-word', // Prevents long words from overflowing
406+
'margin-top': '15px'
407+
});
408+
409+
detailsContent.append('<hr>');
410+
details.forEach((desc, index) => {
411+
detailsContent.append(document.createTextNode(`${index + 1}. ${desc}\n`));
412+
});
413+
$('#id_body').append(detailsContent);
414+
}
415+
397416
if (getStorage("darkMode") == "on")
398417
$('#id_logo').attr("src", 'img/hyperion/logo_negativ.png');
399418

0 commit comments

Comments
 (0)