I have an Interceptor to catch http errors when calling my RESTful service:
services.config(function($httpProvider) {
$httpProvider.responseInterceptors.push('globalInterceptor');
var elementsList = $();
var showMessage = function(content, cl, time) {
$('<div/>')
.addClass(cl)
.hide()
.fadeIn('fast')
.delay(time)
.fadeOut('fast', function() { $(this).remove(); })
.appendTo(elementsList)
.text(content);
};
});
services.factory('globalInterceptor', function($q){
return function(promise){
return promise.then(function(successResponse){
if (typeof(successResponse) !== 'undefined') {
if (successResponse.config.method.toUpperCase() != 'GET') {
showMessage('Success', 'http-success-message', 5000);
return successResponse;
}
}
}, function(errorResponse){
switch (errorResponse.status) {
case 400:
showMessage(errorResponse.data.message, 'http-error-message', 6000);
if(errorResponse.data.errors.length > 0) {
for(var i=0; i<errorResponse.data.errors.length; i++) {
showMessage(errorResponse.data.errors[i],
'http-error-validation-message', 6000);
}
}
break;
case 401:
showMessage('Wrong email address or password!',
'http-error-message', 6000);
break;
case 403:
showMessage('You have insufficient privileges to do what you want to do!',
'http-error-message', 6000);
break;
case 500:
showMessage('Internal server error: ' + errorResponse.data.message,
'http-error-message', 6000);
break;
default:
showMessage('Error ' + errorResponse.status + ': ' + errorResponse.data.message,
'http-error-message', 6000);
}
return $q.reject(errorResponse);
});
}
});
When loading, my login page stops. The problem arose after the nozzle was made before everything worked fine.
This gives me this error message, which really doesn't help:
TypeError: Cannot read property 'data' of undefined
at http://localhost:8080/vendor/angular-1.2.2/angular.js:7479:22
at deferred.promise.then.wrappedCallback (http://localhost:8080/vendor/angular-1.2.2/angular.js:10655:81)
at deferred.promise.then.wrappedCallback (http://localhost:8080/vendor/angular-1.2.2/angular.js:10655:81)
at http://localhost:8080/vendor/angular-1.2.2/angular.js:10741:26
at Scope.$get.Scope.$eval (http://localhost:8080/vendor/angular-1.2.2/angular.js:11634:28)
at Scope.$get.Scope.$digest (http://localhost:8080/vendor/angular-1.2.2/angular.js:11479:31)
at Scope.$get.Scope.$apply (http://localhost:8080/vendor/angular-1.2.2/angular.js:11740:24)
at done (http://localhost:8080/vendor/angular-1.2.2/angular.js:7744:45)
at completeRequest (http://localhost:8080/vendor/angular-1.2.2/angular.js:7918:7)
at XMLHttpRequest.xhr.onreadystatechange (http://localhost:8080/vendor/angular-1.2.2/angular.js:7874:11) angular.js:9159
I tried to debug /console.log this “data” attribute, but I can’t find it ... When the application loads, it receives two files in order (200 and with attr data) and two of these errors.
Any help would be greatly appreciated :-)
source
share