Skip to content

Commit dfa1075

Browse files
committed
frontend: show response errors on frontend
1 parent 5fd46ab commit dfa1075

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

webapp/app.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@ zsd.config(['$routeProvider', function($routeProvider){
1414
otherwise({redirectTo: '/by-file'});
1515
}]);
1616

17+
zsd.config(['$httpProvider', function($httpProvider){
18+
$httpProvider.interceptors.push('HTTPErrorInterceptor');
19+
}]);
20+
21+
zsd.factory('HTTPErrorInterceptor', ['$q', '$rootScope', function($q, $rootScope){
22+
return {
23+
'requestError': function(rejection){
24+
console.log("requestError");
25+
console.log(rejection);
26+
return $q.reject(rejection);
27+
},
28+
'responseError': function(rejection){
29+
// 406 are handled in the controller (file size limit)
30+
if(rejection.status !== 406){
31+
$rootScope.$broadcast('response-error', rejection);
32+
}
33+
return $q.reject(rejection);
34+
}
35+
};
36+
}]);
1737

1838
zsd.factory('Config', ["$http", function($http){
1939
var config;
@@ -191,20 +211,26 @@ zsd.directive('dirBrowser', ['Backend', function(Backend){
191211
};
192212
}]);
193213

194-
zsd.controller('MainCtrl', ["$location", "Config", function($location, Config){
214+
zsd.controller('MainCtrl', ['$location', '$rootScope', 'Config', function($location, $rootScope, Config){
195215
var self = this;
196216

197217

218+
198219
Config.promise.then(function(){
199220
self.config = Config.config();
200221
});
201222

223+
$rootScope.$on('response-error', function(event, args){
224+
self.error = args.data;
225+
});
202226

203227

204228
self.activeClassIfAt = function(path){
205229
return {active: $location.path() === path};
206230
};
207231

232+
233+
208234
}]);
209235

210236

webapp/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@
7070
</div>
7171

7272

73+
<!-- error -->
74+
<div class="container alert alert-danger" ng-show="mainCtrl.error">
75+
<span class="glyphicon glyphicon-remove" ng-click="mainCtrl.error = ''"></span>
76+
{{mainCtrl.error}}
77+
</div>
78+
7379
<!-- content -->
7480
<div ng-view/>
7581

0 commit comments

Comments
 (0)