web: Remove nonsense round-trip through JSON.parse() + JSON.stringify().

This commit is contained in:
Alex Vandiver 2023-07-18 18:16:18 +00:00 committed by Tim Abbott
parent d05a9d4000
commit d05a1e9efa
3 changed files with 4 additions and 23 deletions

View File

@ -221,8 +221,6 @@ function show_modal() {
error(xhr) { error(xhr) {
$("#dialog_error").hide(); $("#dialog_error").hide();
dialog_widget.hide_dialog_spinner(); dialog_widget.hide_dialog_spinner();
const errors = JSON.parse(xhr.responseText).msg;
xhr.responseText = JSON.stringify({msg: errors});
ui_report.error($t_html({defaultMessage: "Failed"}), xhr, $emoji_status); ui_report.error($t_html({defaultMessage: "Failed"}), xhr, $emoji_status);
}, },
}); });

View File

@ -216,8 +216,6 @@ export function populate_user_groups() {
setTimeout(show_saved_button, 200); setTimeout(show_saved_button, 200);
}, },
error(xhr) { error(xhr) {
const errors = JSON.parse(xhr.responseText).msg;
xhr.responseText = JSON.stringify({msg: errors});
ui_report.error($t_html({defaultMessage: "Failed"}), xhr, $user_group_status); ui_report.error($t_html({defaultMessage: "Failed"}), xhr, $user_group_status);
update_cancel_button(); update_cancel_button();
$(`#user-groups #${CSS.escape(data.id)} .name`).text(group_data.name); $(`#user-groups #${CSS.escape(data.id)} .name`).text(group_data.name);
@ -324,8 +322,6 @@ export function add_user_group() {
}, },
error(xhr) { error(xhr) {
$user_group_status.hide(); $user_group_status.hide();
const errors = JSON.parse(xhr.responseText).msg;
xhr.responseText = JSON.stringify({msg: errors});
ui_report.error($t_html({defaultMessage: "Failed"}), xhr, $user_group_status); ui_report.error($t_html({defaultMessage: "Failed"}), xhr, $user_group_status);
}, },
}); });

View File

@ -538,21 +538,14 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
assert.ok(!$("#dialog_error").visible()); assert.ok(!$("#dialog_error").visible());
})(); })();
(function test_post_error() { (function test_post_error() {
$("#dialog_error").show(); $("#dialog_error").show();
ui_report.error = (error_msg, error_obj, ele) => { ui_report.error = (error_msg, error_obj, ele) => {
const xhr = {
responseText: '{"msg":"fake-msg"}',
};
assert.equal(error_msg, "translated HTML: Failed"); assert.equal(error_msg, "translated HTML: Failed");
assert.deepEqual(error_obj, xhr); assert.deepEqual(error_obj, {responseJson: {msg: "fake-msg"}});
assert.equal(ele, $("#dialog_error")); assert.equal(ele, $("#dialog_error"));
}; };
const xhr = { opts.error({responseJson: {msg: "fake-msg"}});
responseText: '{"msg":"fake-msg", "attrib":"val"}',
};
opts.error(xhr);
assert.ok(!$("#dialog_error").visible()); assert.ok(!$("#dialog_error").visible());
})(); })();
@ -763,17 +756,11 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
const $user_group_error = $(user_group_selector + " .user-group-status"); const $user_group_error = $(user_group_selector + " .user-group-status");
$user_group_error.show(); $user_group_error.show();
ui_report.error = (error_msg, error_obj, ele) => { ui_report.error = (error_msg, error_obj, ele) => {
const xhr = {
responseText: '{"msg":"fake-msg"}',
};
assert.equal(error_msg, "translated HTML: Failed"); assert.equal(error_msg, "translated HTML: Failed");
assert.deepEqual(error_obj, xhr); assert.deepEqual(error_obj, {responseJson: {msg: "fake-msg"}});
assert.equal(ele, $user_group_error); assert.equal(ele, $user_group_error);
}; };
const xhr = { opts.error({responseJson: {msg: "fake-msg"}});
responseText: '{"msg":"fake-msg", "attrib":"val"}',
};
opts.error(xhr);
assert.ok($user_group_error.visible()); assert.ok($user_group_error.visible());
})(); })();