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.

channel: Fix implicit use of any.

Anders Kaseorgb59b3f69526e
diff --git a/web/src/channel.ts b/web/src/channel.ts
index 1e9d4d020c5..e34b5c6f488 100644
--- a/web/src/channel.ts
+++ b/web/src/channel.ts
@@ -1,6 +1,7 @@
import * as Sentry from "@sentry/browser";
import $ from "jquery";
import _ from "lodash";
+import {z} from "zod";
import {page_params} from "./base_page_params";
import * as blueslip from "./blueslip";
@@ -131,7 +132,7 @@ function call(args: AjaxRequestHandlerOptions): JQuery.jqXHR<unknown> | undefine
args,
});
} else if (
- xhr.responseJSON.code === "CSRF_FAILED" &&
+ z.object({code: z.literal("CSRF_FAILED")}).safeParse(xhr.responseJSON).success &&
reload_state.csrf_failed_handler !== undefined
) {
reload_state.csrf_failed_handler();
@@ -210,10 +211,15 @@ export function patch(
}
export function xhr_error_message(message: string, xhr: JQuery.jqXHR<unknown>): string {
- if (xhr.status >= 400 && xhr.status < 500 && xhr.responseJSON?.msg) {
+ let parsed;
+ if (
+ xhr.status >= 400 &&
+ xhr.status < 500 &&
+ (parsed = z.object({msg: z.string()}).safeParse(xhr.responseJSON)).success
+ ) {
// Only display the error response for 4XX, where we've crafted
// a nice response.
- const server_response_html = _.escape(xhr.responseJSON.msg);
+ const server_response_html = _.escape(parsed.data.msg);
if (message) {
message += ": " + server_response_html;
} else {