Skip to content

Commit

Permalink
refs #5102 display an error message in case we cannot load any angula…
Browse files Browse the repository at this point in the history
…rjs html template
  • Loading branch information
tsteur committed May 9, 2014
1 parent 89d9003 commit 3ba1bdc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/CoreHome/CoreHome.php
Expand Up @@ -119,6 +119,7 @@ public function getJsFiles(&$jsFiles)

$jsFiles[] = "plugins/CoreHome/angularjs/piwikApp.js";
$jsFiles[] = "plugins/CoreHome/angularjs/anchorLinkFix.js";
$jsFiles[] = "plugins/CoreHome/angularjs/http404check.js";

$jsFiles[] = "plugins/CoreHome/angularjs/siteselector/siteselector-model.js";
$jsFiles[] = "plugins/CoreHome/angularjs/siteselector/siteselector-controller.js";
Expand Down
37 changes: 37 additions & 0 deletions plugins/CoreHome/angularjs/http404check.js
@@ -0,0 +1,37 @@
angular.module('piwikApp').factory('http404CheckInterceptor', function($q) {

function isClientError(rejection)
{
return rejection.status >= 400 && rejection.status < 408;
}

return {

'responseError': function(rejection) {
if (rejection
&& isClientError(rejection)
&& rejection.config
&& rejection.config.url
&& -1 !== rejection.config.url.indexOf('.html')
&& -1 !== rejection.config.url.indexOf('plugins')) {

var message = 'Please check your server configuration. You may want to whitelist "*.html" files from the "plugins" directory.';
message += ' The HTTP status code is ' + rejection.status;

var UI = require('piwik/UI');
var notification = new UI.Notification();
notification.show(message, {
title: 'Failed to load HTML file:',
context: 'error',
id: 'Network_HtmlFileLoadingError'
});
}

return $q.reject(rejection);
}
};
});

angular.module('piwikApp').config(['$httpProvider',function($httpProvider) {
$httpProvider.interceptors.push('http404CheckInterceptor');
}]);

0 comments on commit 3ba1bdc

Please sign in to comment.