Handle errors with ProcessErrors

This commit is contained in:
Marliana Lara
2017-10-19 14:59:49 -04:00
parent cee81e9df6
commit 32da686724
6 changed files with 32 additions and 21 deletions

View File

@@ -275,8 +275,11 @@ export default
})); }));
$scope.credential_types = credential_types; $scope.credential_types = credential_types;
}) })
.catch( (error) => { .catch(({data, status}) => {
console.log(error); ProcessErrors($scope, data, status, null, {
hdr: 'Error!',
msg: 'Failed to get credential types. GET status: ' + status
});
}); });
// Figure out which step the user needs to start on // Figure out which step the user needs to start on

View File

@@ -116,7 +116,7 @@
function retrieveStatus(id) { function retrieveStatus(id) {
setTimeout(function() { setTimeout(function() {
var url = GetBasePath('notifications') + id; let url = GetBasePath('notifications') + id;
Rest.setUrl(url); Rest.setUrl(url);
Rest.get() Rest.get()
.then(function(res) { .then(function(res) {
@@ -142,9 +142,12 @@
} }
}) })
.catch( (error) => { .catch(({data, status}) => {
console.log(error); ProcessErrors($scope, data, status, null, {
}) hdr: 'Error!',
msg: 'Failed to get ' + url + '. GET status: ' + status
});
});
}, 5000); }, 5000);
} }
}; };

View File

@@ -61,7 +61,7 @@ export default
ParentObject: ['$stateParams', 'Rest', 'GetBasePath', function($stateParams, Rest, GetBasePath){ ParentObject: ['$stateParams', 'Rest', 'GetBasePath', function($stateParams, Rest, GetBasePath){
let path = `${GetBasePath('job_templates')}${$stateParams.id}`; let path = `${GetBasePath('job_templates')}${$stateParams.id}`;
Rest.setUrl(path); Rest.setUrl(path);
return Rest.get(path).then(response => response.data) return Rest.get(path).then(response => response.data);
}], }],
UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q', UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q',
function(Rest, GetBasePath, $stateParams, $q) { function(Rest, GetBasePath, $stateParams, $q) {
@@ -152,7 +152,7 @@ export default
ParentObject: ['$stateParams', 'Rest', 'GetBasePath', function($stateParams, Rest, GetBasePath){ ParentObject: ['$stateParams', 'Rest', 'GetBasePath', function($stateParams, Rest, GetBasePath){
let path = `${GetBasePath('workflow_job_templates')}${$stateParams.id}`; let path = `${GetBasePath('workflow_job_templates')}${$stateParams.id}`;
Rest.setUrl(path); Rest.setUrl(path);
return Rest.get(path).then(response => response.data) return Rest.get(path).then(response => response.data);
}], }],
UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q', UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q',
function(Rest, GetBasePath, $stateParams, $q) { function(Rest, GetBasePath, $stateParams, $q) {
@@ -242,7 +242,7 @@ export default
ParentObject: ['$stateParams', 'Rest', 'GetBasePath', function($stateParams, Rest, GetBasePath){ ParentObject: ['$stateParams', 'Rest', 'GetBasePath', function($stateParams, Rest, GetBasePath){
let path = `${GetBasePath('projects')}${$stateParams.id}`; let path = `${GetBasePath('projects')}${$stateParams.id}`;
Rest.setUrl(path); Rest.setUrl(path);
return Rest.get(path).then(response => response.data) return Rest.get(path).then(response => response.data);
}], }],
UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q', UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q',
function(Rest, GetBasePath, $stateParams, $q) { function(Rest, GetBasePath, $stateParams, $q) {

View File

@@ -22,7 +22,8 @@ export default
if (data.actions.POST) { if (data.actions.POST) {
canAddVal.resolve({canAdd: true, options: data}); canAddVal.resolve({canAdd: true, options: data});
} else { } else {
canAddVal.resolve({canAdd: false}) } canAddVal.resolve({canAdd: false});
}
Wait("stop"); Wait("stop");
}); });

View File

@@ -99,8 +99,7 @@ export default
} }
}) })
.catch( (error) => { .catch( (error) => {
console.log(error); if (error.status_code === 403) {
if (status_code === 403) {
/* user doesn't have access to see the project, no big deal. */ /* user doesn't have access to see the project, no big deal. */
$scope.disablePlaybookBecausePermissionDenied = true; $scope.disablePlaybookBecausePermissionDenied = true;
} else { } else {
@@ -144,9 +143,12 @@ export default
.then(function(){ .then(function(){
Wait('stop'); Wait('stop');
}) })
.catch( (error) => { .catch(({data, status}) => {
console.log(error); ProcessErrors($scope, data, status, null, {
}) hdr: 'Error!',
msg: 'Call failed. Returned status: ' + status
});
});
} }
} }
}); });

View File

@@ -210,13 +210,15 @@ export default ['$scope', '$rootScope',
$state.go('templates.editJobTemplate', {job_template_id: results.id}, {reload: true}); $state.go('templates.editJobTemplate', {job_template_id: results.id}, {reload: true});
} }
}) })
.catch((error)=> { .catch(({data, status}) => {
console.log(error); ProcessErrors($scope, data, status, null, {
}) hdr: 'Error!',
msg: 'Call failed. Return status: ' + status
});
});
}) })
.catch((error) => { .catch(({data, status}) => {
console.log(error); ProcessErrors($rootScope, data, status, null, {hdr: 'Error!',
ProcessErrors($rootScope, error, status, null, {hdr: 'Error!',
msg: 'Call failed. Return status: '+ status}); msg: 'Call failed. Return status: '+ status});
}); });
} }