web: Do not assume error responses are valid, or our, JSON.

Partially fixes #24815.
This commit is contained in:
Alex Vandiver
2023-07-18 18:19:22 +00:00
committed by Tim Abbott
parent 7efe989a72
commit ba7492a314
21 changed files with 109 additions and 83 deletions

View File

@@ -583,10 +583,14 @@ export function initialize() {
$invite_row.remove();
}
function failure(error_msg) {
function xhr_failure(xhr) {
let error_message = "Failed to subscribe user!";
if (xhr.responseJSON?.msg) {
error_message = xhr.responseJSON.msg;
}
clear_invites();
compose_banner.show_error_message(
error_msg,
error_message,
compose_banner.CLASSNAMES.generic_compose_error,
$banner_container,
$("#compose-textarea"),
@@ -594,11 +598,6 @@ export function initialize() {
$(event.target).prop("disabled", true);
}
function xhr_failure(xhr) {
const error = xhr.responseJSON;
failure(error.msg);
}
const sub = sub_store.get(stream_id);
subscriber_api.add_user_ids_to_stream([user_id], sub, success, xhr_failure);