From df42d11e0e80b65fdf19b62351dbdb9442e62529 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 22 Apr 2021 14:39:20 +0200 Subject: [PATCH] Fix backwards compatibility of AJAX failure callback Fixes #4088 --- ts/WoltLabSuite/Core/Ajax/Request.ts | 4 +++- wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Request.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ts/WoltLabSuite/Core/Ajax/Request.ts b/ts/WoltLabSuite/Core/Ajax/Request.ts index 9a533ba156..928010c51b 100644 --- a/ts/WoltLabSuite/Core/Ajax/Request.ts +++ b/ts/WoltLabSuite/Core/Ajax/Request.ts @@ -278,7 +278,9 @@ class AjaxRequest { let showError = true; if (typeof options.failure === "function") { - showError = options.failure(data || {}, xhr.responseText || "", xhr, options.data!); + // undefined might be returned by legacy callbacks and must be treated as 'true'. + const result = options.failure(data || {}, xhr.responseText || "", xhr, options.data!) as boolean | undefined; + showError = result !== false; } if (options.ignoreError !== true && showError) { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Request.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Request.js index c00e0b6722..37da9d0885 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Request.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Request.js @@ -233,7 +233,9 @@ define(["require", "exports", "tslib", "./Status", "../Core", "../Dom/Change/Lis } let showError = true; if (typeof options.failure === "function") { - showError = options.failure(data || {}, xhr.responseText || "", xhr, options.data); + // undefined might be returned by legacy callbacks and must be treated as 'true'. + const result = options.failure(data || {}, xhr.responseText || "", xhr, options.data); + showError = result !== false; } if (options.ignoreError !== true && showError) { const html = this.getErrorHtml(data, xhr); -- 2.20.1