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.

settings_linkifiers: Fix implicit use of any.

Anders Kaseorg70d140ec597f
diff --git a/web/src/settings_linkifiers.ts b/web/src/settings_linkifiers.ts
index 2af482576ba..1d4ad92191a 100644
--- a/web/src/settings_linkifiers.ts
+++ b/web/src/settings_linkifiers.ts
@@ -70,9 +70,12 @@ function open_linkifier_edit_form(linkifier_id: number): void {
},
error_continuation(xhr: JQuery.jqXHR<unknown>) {
$change_linkifier_button.prop("disabled", false);
- if (xhr.responseJSON?.errors) {
+ const parsed = z
+ .object({errors: z.record(z.array(z.string()).optional())})
+ .safeParse(xhr.responseJSON);
+ if (parsed.success) {
handle_linkifier_api_error(
- xhr,
+ parsed.data.errors,
$pattern_status,
$template_status,
$dialog_error_element,
@@ -119,7 +122,7 @@ function update_linkifiers_order(): void {
}
function handle_linkifier_api_error(
- xhr: JQuery.jqXHR<unknown>,
+ errors: Record<string, string[] | undefined>,
pattern_status: JQuery,
template_status: JQuery,
linkifier_status: JQuery,
@@ -127,7 +130,6 @@ function handle_linkifier_api_error(
// The endpoint uses the Django ValidationError system for error
// handling, which returns somewhat complicated error
// dictionaries. This logic parses them.
- const errors = xhr.responseJSON.errors;
if (errors.pattern !== undefined) {
ui_report.error(
$t_html({defaultMessage: "Failed: {error}"}, {error: errors.pattern[0]}),
@@ -272,9 +274,12 @@ export function build_page(): void {
},
error(xhr) {
$add_linkifier_button.prop("disabled", false);
- if (xhr.responseJSON?.errors) {
+ const parsed = z
+ .object({errors: z.record(z.array(z.string()).optional())})
+ .safeParse(xhr.responseJSON);
+ if (parsed.success) {
handle_linkifier_api_error(
- xhr,
+ parsed.data.errors,
$pattern_status,
$template_status,
$linkifier_status,