Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
channel: Refactor xhr_error_message to accept message optionally.
Daniil Fadeev0756ac925056
diff --git a/web/src/channel.js b/web/src/channel.jsindex 1abd8310cad..88fefeb289c 100644--- a/web/src/channel.js+++ b/web/src/channel.js@@ -1,4 +1,5 @@import $ from "jquery";+import _ from "lodash";import * as blueslip from "./blueslip";import {page_params} from "./page_params";@@ -150,7 +151,12 @@ export function xhr_error_message(message, xhr) {if (xhr.status.toString().charAt(0) === "4") {// Only display the error response for 4XX, where we've crafted// a nice response.- message += ": " + JSON.parse(xhr.responseText).msg;+ const server_response_html = _.escape(JSON.parse(xhr.responseText).msg);+ if (message) {+ message += ": " + server_response_html;+ } else {+ message = server_response_html;+ }}return message;}diff --git a/web/tests/channel.test.js b/web/tests/channel.test.jsindex 428a7f094a5..89da9ebbdd4 100644--- a/web/tests/channel.test.js+++ b/web/tests/channel.test.js@@ -343,6 +343,9 @@ test("xhr_error_message", () => {};msg = "some message";assert.equal(channel.xhr_error_message(msg, xhr), "some message: file not found");++ msg = null;+ assert.equal(channel.xhr_error_message(msg, xhr), "file not found");});test("while_reloading", () => {