Enh: Javascript HumHub Client - better handle ajax redirects

This commit is contained in:
Lucas Bartholemy 2017-02-13 19:35:24 +01:00
parent c049a3d4a5
commit ae9951e02f
2 changed files with 18 additions and 2 deletions

View File

@ -22,6 +22,7 @@ HumHub Change Log
- Fix: Richtext with emoji only on post edit where ignored.
- Fix: File StorageManager setContent method broken
- Enh: Added FileHelper methods createLink & getContentContainer
- Enh: Javascript HumHub Client - better handle ajax redirects
1.2.0-beta.1 (February 08, 2017)
--------------------------------

View File

@ -17,8 +17,8 @@ humhub.module('client', function (module, require, $) {
//Textstatus = "timeout", "error", "abort", "parsererror", "application"
this.textStatus = textStatus;
this.dataType = dataType;
var responseType = xhr.getResponseHeader('content-type');
var responseType = xhr.getResponseHeader('content-type');
// If we expect json and received json we merge the json result with our response object.
if ((!dataType || dataType === 'json') && responseType && responseType.indexOf('json') > -1) {
@ -162,6 +162,21 @@ humhub.module('client', function (module, require, $) {
var error = function (xhr, textStatus, errorThrown) {
var response = new Response(xhr, url, textStatus, cfg.dataType).setError(errorThrown);
if (response.status == 302) {
url = null;
if (xhr.getResponseHeader('X-Pjax-Url')) {
url = xhr.getResponseHeader('X-Pjax-Url');
} else {
url = xhr.getResponseHeader('X-Redirect');
}
if (url !== null) {
document.location = url;
return;
}
}
if (errorHandler && object.isFunction(errorHandler)) {
errorHandler(response);
}