浏览代码

HUE-6885 [frontend] Catch all http 502 and show an HTML stripped version of the message

Enrico Berti 8 年之前
父节点
当前提交
773bb39
共有 1 个文件被更改,包括 18 次插入3 次删除
  1. 18 3
      desktop/core/src/desktop/templates/common_header_footer_components.mako

+ 18 - 3
desktop/core/src/desktop/templates/common_header_footer_components.mako

@@ -262,11 +262,26 @@ from metadata.conf import has_optimizer, OPTIMIZER
       return mTime;
     };
 
-    //Add CSRF Token to all XHR Requests
-    var xrhsend = XMLHttpRequest.prototype.send;
+    // catches HTTP 502 errors
+    function xhrOnreadystatechange() {
+      if (this.readyState === 4 && this.status === 502) {
+        $.jHueNotify.error($('<span>').html(this.responseText).text());
+      }
+      if (this._onreadystatechange) {
+        return this._onreadystatechange.apply(this, arguments);
+      }
+    }
+
+    var xhrSend = XMLHttpRequest.prototype.send;
     XMLHttpRequest.prototype.send = function (data) {
+      // Add CSRF Token to all XHR Requests
       this.setRequestHeader('X-CSRFToken', window.CSRF_TOKEN);
-      return xrhsend.apply(this, arguments);
+
+      if (this.onreadystatechange) {
+        this._onreadystatechange = this.onreadystatechange;
+      }
+      this.onreadystatechange = xhrOnreadystatechange;
+      return xhrSend.apply(this, arguments);
     };
     XMLHttpRequest.prototype.isAugmented = true;