Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

ui_report: Reuse `channel.xhr_error_message` function in `error` method.

Lalit Kumar Singhcfe2ddb091f4
diff --git a/web/src/channel.ts b/web/src/channel.ts
index 28db6b885b9..99ed65bdaa4 100644
--- a/web/src/channel.ts
+++ b/web/src/channel.ts
@@ -201,10 +201,7 @@ export function patch(
return post(options);
}
-export function xhr_error_message(
- message: string | null,
- xhr: JQuery.jqXHR<unknown>,
-): string | null {
+export function xhr_error_message(message: string, xhr: JQuery.jqXHR<unknown>): string {
if (xhr.status.toString().charAt(0) === "4" && xhr.responseJSON?.msg) {
// Only display the error response for 4XX, where we've crafted
// a nice response.
diff --git a/web/src/message_edit.js b/web/src/message_edit.js
index b6c6fc9a4dc..ca6fae36f01 100644
--- a/web/src/message_edit.js
+++ b/web/src/message_edit.js
@@ -1032,7 +1032,7 @@ export function save_message_row_edit($row) {
}
hide_message_edit_spinner($row);
- const message = channel.xhr_error_message(null, xhr);
+ const message = channel.xhr_error_message("", xhr);
const $container = compose_banner.get_compose_banner_container(
$row.find("textarea"),
);
diff --git a/web/src/ui_report.ts b/web/src/ui_report.ts
index a3e938768ac..9a980f6c496 100644
--- a/web/src/ui_report.ts
+++ b/web/src/ui_report.ts
@@ -1,6 +1,6 @@
import $ from "jquery";
-import _ from "lodash";
+import * as channel from "./channel";
import * as common from "./common";
import {$t} from "./i18n";
@@ -38,18 +38,8 @@ export function error(
status_box: JQuery,
remove_after?: number,
): void {
- if (xhr && xhr.status >= 400 && xhr.status < 500 && xhr.responseJSON?.msg) {
- // Only display the error response for 4XX, where we've crafted
- // a nice response.
- const server_response_html = _.escape(xhr.responseJSON.msg);
- if (response_html) {
- response_html += ": " + server_response_html;
- } else {
- response_html = server_response_html;
- }
- }
-
- message(response_html, status_box, "alert-error", remove_after);
+ const msg = xhr ? channel.xhr_error_message(response_html, xhr) : response_html;
+ message(msg, status_box, "alert-error", remove_after);
}
export function client_error(
diff --git a/web/tests/channel.test.js b/web/tests/channel.test.js
index c2dd86517f7..87e95c9e5aa 100644
--- a/web/tests/channel.test.js
+++ b/web/tests/channel.test.js
@@ -348,7 +348,7 @@ test("xhr_error_message", () => {
msg = "some message";
assert.equal(channel.xhr_error_message(msg, xhr), "some message: file not found");
- msg = null;
+ msg = "";
assert.equal(channel.xhr_error_message(msg, xhr), "file not found");
});