error handler
This commit is contained in:
parent
cc8aecab76
commit
98c745014c
3 changed files with 55 additions and 14 deletions
18
angular_app/js/app.js
vendored
18
angular_app/js/app.js
vendored
|
@ -34,6 +34,24 @@ eventManApp.run(['$rootScope', '$state', '$stateParams', '$log',
|
|||
$log.debug('App UUID: ' + $rootScope.app_uuid);
|
||||
$rootScope.$state = $state;
|
||||
$rootScope.$stateParams = $stateParams;
|
||||
|
||||
$rootScope.error = {error: false};
|
||||
|
||||
$rootScope.errorHandler = function(response) {
|
||||
$log.debug('Handling error message:');
|
||||
$log.debug(response);
|
||||
$rootScope.error.status = response.status;
|
||||
$rootScope.error.statusText = response.statusText;
|
||||
if (response.data && response.data.error) {
|
||||
$rootScope.error.code = response.data.code;
|
||||
$rootScope.error.message = response.data.message;
|
||||
$rootScope.error.error = true;
|
||||
} else {
|
||||
$rootScope.error.code = null;
|
||||
$rootScope.error.message = '';
|
||||
$rootScope.error.error = false;
|
||||
}
|
||||
};
|
||||
}]
|
||||
);
|
||||
|
||||
|
|
6
angular_app/js/controllers.js
vendored
6
angular_app/js/controllers.js
vendored
|
@ -7,8 +7,8 @@ var eventManControllers = angular.module('eventManControllers', []);
|
|||
|
||||
|
||||
/* A controller that can be used to navigate. */
|
||||
eventManControllers.controller('NavigationCtrl', ['$scope', '$location', 'Setting', 'Info',
|
||||
function ($scope, $location, Setting, Info) {
|
||||
eventManControllers.controller('NavigationCtrl', ['$scope', '$rootScope', '$location', 'Setting', 'Info',
|
||||
function ($scope, $rootScope, $location, Setting, Info) {
|
||||
$scope.logo = {};
|
||||
|
||||
$scope.go = function(url) {
|
||||
|
@ -22,7 +22,7 @@ eventManControllers.controller('NavigationCtrl', ['$scope', '$location', 'Settin
|
|||
});
|
||||
|
||||
Info.get({}, function(data) {
|
||||
$scope.current_user = data.current_user || '';
|
||||
$rootScope.info = data || {};
|
||||
});
|
||||
|
||||
$scope.isActive = function(view) {
|
||||
|
|
45
angular_app/js/services.js
vendored
45
angular_app/js/services.js
vendored
|
@ -22,6 +22,7 @@ eventManServices.factory('Event', ['$resource', '$rootScope',
|
|||
|
||||
all: {
|
||||
method: 'GET',
|
||||
interceptor : {responseError: $rootScope.errorHandler},
|
||||
isArray: true,
|
||||
transformResponse: function(data, headers) {
|
||||
data = angular.fromJson(data);
|
||||
|
@ -32,7 +33,9 @@ eventManServices.factory('Event', ['$resource', '$rootScope',
|
|||
}
|
||||
},
|
||||
|
||||
get: {method: 'GET',
|
||||
get: {
|
||||
method: 'GET',
|
||||
interceptor : {responseError: $rootScope.errorHandler},
|
||||
transformResponse: function(data, headers) {
|
||||
data = angular.fromJson(data);
|
||||
convert_dates(data);
|
||||
|
@ -48,10 +51,14 @@ eventManServices.factory('Event', ['$resource', '$rootScope',
|
|||
}
|
||||
},
|
||||
|
||||
update: {method: 'PUT'},
|
||||
update: {
|
||||
method: 'PUT',
|
||||
interceptor : {responseError: $rootScope.errorHandler}
|
||||
},
|
||||
|
||||
updatePerson: {
|
||||
method: 'PUT',
|
||||
interceptor : {responseError: $rootScope.errorHandler},
|
||||
isArray: false,
|
||||
url: 'events/:id/persons/:person_id',
|
||||
params: {uuid: $rootScope.app_uuid},
|
||||
|
@ -62,6 +69,7 @@ eventManServices.factory('Event', ['$resource', '$rootScope',
|
|||
|
||||
addPerson: {
|
||||
method: 'POST',
|
||||
interceptor : {responseError: $rootScope.errorHandler},
|
||||
isArray: false,
|
||||
url: 'events/:id/persons/:person_id',
|
||||
params: {uuid: $rootScope.app_uuid},
|
||||
|
@ -72,6 +80,7 @@ eventManServices.factory('Event', ['$resource', '$rootScope',
|
|||
|
||||
deletePerson: {
|
||||
method: 'DELETE',
|
||||
interceptor : {responseError: $rootScope.errorHandler},
|
||||
isArray: false,
|
||||
url: 'events/:_id/persons/:person_id',
|
||||
params: {uuid: $rootScope.app_uuid},
|
||||
|
@ -84,26 +93,34 @@ eventManServices.factory('Event', ['$resource', '$rootScope',
|
|||
);
|
||||
|
||||
|
||||
eventManServices.factory('Person', ['$resource',
|
||||
function($resource) {
|
||||
eventManServices.factory('Person', ['$resource', '$rootScope',
|
||||
function($resource, $rootScope) {
|
||||
return $resource('persons/:id', {id: '@_id'}, {
|
||||
|
||||
all: {
|
||||
method: 'GET',
|
||||
interceptor : {responseError: $rootScope.errorHandler},
|
||||
isArray: true,
|
||||
transformResponse: function(data, headers) {
|
||||
return angular.fromJson(data).persons;
|
||||
}
|
||||
},
|
||||
|
||||
update: {method: 'PUT'},
|
||||
update: {
|
||||
method: 'PUT',
|
||||
interceptor : {responseError: $rootScope.errorHandler}
|
||||
},
|
||||
|
||||
getEvents: {
|
||||
method: 'GET',
|
||||
interceptor : {responseError: $rootScope.errorHandler},
|
||||
url: 'persons/:_id/events',
|
||||
isArray: true,
|
||||
transformResponse: function(data, headers) {
|
||||
data = angular.fromJson(data);
|
||||
if (data.error) {
|
||||
return data;
|
||||
}
|
||||
angular.forEach(data.events || [], function(event_, event_idx) {
|
||||
convert_dates(event_);
|
||||
});
|
||||
|
@ -115,28 +132,34 @@ eventManServices.factory('Person', ['$resource',
|
|||
);
|
||||
|
||||
|
||||
eventManServices.factory('Setting', ['$resource',
|
||||
function($resource) {
|
||||
eventManServices.factory('Setting', ['$resource', '$rootScope',
|
||||
function($resource, $rootScope) {
|
||||
return $resource('settings/', {}, {
|
||||
|
||||
query: {
|
||||
method: 'GET',
|
||||
interceptor : {responseError: $rootScope.errorHandler},
|
||||
isArray: true,
|
||||
transformResponse: function(data, headers) {
|
||||
return angular.fromJson(data).settings;
|
||||
}
|
||||
},
|
||||
|
||||
update: {method: 'PUT'}
|
||||
update: {
|
||||
method: 'PUT',
|
||||
interceptor : {responseError: $rootScope.errorHandler}
|
||||
}
|
||||
});
|
||||
}]
|
||||
);
|
||||
|
||||
|
||||
eventManServices.factory('Info', ['$resource',
|
||||
function($resource) {
|
||||
eventManServices.factory('Info', ['$resource', '$rootScope',
|
||||
function($resource, $rootScope) {
|
||||
return $resource('info/', {}, {
|
||||
get: {method: 'GET',
|
||||
get: {
|
||||
method: 'GET',
|
||||
interceptor : {responseError: $rootScope.errorHandler},
|
||||
isArray: false,
|
||||
transformResponse: function(data, headers) {
|
||||
return angular.fromJson(data).info || {};
|
||||
|
|
Loading…
Reference in a new issue