Ensure that Ajax/Request calls the `failure` callback for all errors
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 29 Mar 2017 21:24:29 +0000 (23:24 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 29 Mar 2017 21:25:56 +0000 (23:25 +0200)
Previously errors such as broken TCP connections / closed ports
would not call `failure`, because the reply wasn't valid JSON.

wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Request.js

index 05558f4623315f1c52077706c748fdf01ee07852..9e5a23e4de9e0a0a09674287b9f0912499674bf4 100644 (file)
@@ -272,8 +272,8 @@ define(['Core', 'Language', 'Dom/ChangeListener', 'Dom/Util', 'Ui/Dialog', 'Wolt
                        catch (e) {}
                        
                        var showError = true;
-                       if (data !== null && typeof options.failure === 'function') {
-                               showError = options.failure(data, xhr.responseText, xhr, options.data);
+                       if (typeof options.failure === 'function') {
+                               showError = options.failure((data || {}), (xhr.responseText || ''), xhr, options.data);
                        }
                        
                        if (options.ignoreError !== true && showError !== false) {