From 32da68672416da58b6efbc7526efbed733867070 Mon Sep 17 00:00:00 2001 From: Marliana Lara Date: Thu, 19 Oct 2017 14:59:49 -0400 Subject: [PATCH] Handle errors with ProcessErrors --- .../job-submission/job-submission.controller.js | 7 +++++-- .../notification-templates-list/list.controller.js | 11 +++++++---- awx/ui/client/src/scheduler/main.js | 6 +++--- awx/ui/client/src/shared/rbacUiControl.js | 3 ++- .../job-template-edit.controller.js | 12 +++++++----- .../templates/list/templates-list.controller.js | 14 ++++++++------ 6 files changed, 32 insertions(+), 21 deletions(-) diff --git a/awx/ui/client/src/job-submission/job-submission.controller.js b/awx/ui/client/src/job-submission/job-submission.controller.js index f79a927539..97f4002119 100644 --- a/awx/ui/client/src/job-submission/job-submission.controller.js +++ b/awx/ui/client/src/job-submission/job-submission.controller.js @@ -275,8 +275,11 @@ export default })); $scope.credential_types = credential_types; }) - .catch( (error) => { - console.log(error); + .catch(({data, status}) => { + 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 diff --git a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js index 599e17bb67..6a6cf071e4 100644 --- a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js +++ b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js @@ -116,7 +116,7 @@ function retrieveStatus(id) { setTimeout(function() { - var url = GetBasePath('notifications') + id; + let url = GetBasePath('notifications') + id; Rest.setUrl(url); Rest.get() .then(function(res) { @@ -142,9 +142,12 @@ } }) - .catch( (error) => { - console.log(error); - }) + .catch(({data, status}) => { + ProcessErrors($scope, data, status, null, { + hdr: 'Error!', + msg: 'Failed to get ' + url + '. GET status: ' + status + }); + }); }, 5000); } }; diff --git a/awx/ui/client/src/scheduler/main.js b/awx/ui/client/src/scheduler/main.js index 735dd3b804..6dbaf01971 100644 --- a/awx/ui/client/src/scheduler/main.js +++ b/awx/ui/client/src/scheduler/main.js @@ -61,7 +61,7 @@ export default ParentObject: ['$stateParams', 'Rest', 'GetBasePath', function($stateParams, Rest, GetBasePath){ let path = `${GetBasePath('job_templates')}${$stateParams.id}`; Rest.setUrl(path); - return Rest.get(path).then(response => response.data) + return Rest.get(path).then(response => response.data); }], UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q', function(Rest, GetBasePath, $stateParams, $q) { @@ -152,7 +152,7 @@ export default ParentObject: ['$stateParams', 'Rest', 'GetBasePath', function($stateParams, Rest, GetBasePath){ let path = `${GetBasePath('workflow_job_templates')}${$stateParams.id}`; Rest.setUrl(path); - return Rest.get(path).then(response => response.data) + return Rest.get(path).then(response => response.data); }], UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q', function(Rest, GetBasePath, $stateParams, $q) { @@ -242,7 +242,7 @@ export default ParentObject: ['$stateParams', 'Rest', 'GetBasePath', function($stateParams, Rest, GetBasePath){ let path = `${GetBasePath('projects')}${$stateParams.id}`; Rest.setUrl(path); - return Rest.get(path).then(response => response.data) + return Rest.get(path).then(response => response.data); }], UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q', function(Rest, GetBasePath, $stateParams, $q) { diff --git a/awx/ui/client/src/shared/rbacUiControl.js b/awx/ui/client/src/shared/rbacUiControl.js index 2085f9cde9..b65c6c57bd 100644 --- a/awx/ui/client/src/shared/rbacUiControl.js +++ b/awx/ui/client/src/shared/rbacUiControl.js @@ -22,7 +22,8 @@ export default if (data.actions.POST) { canAddVal.resolve({canAdd: true, options: data}); } else { - canAddVal.resolve({canAdd: false}) } + canAddVal.resolve({canAdd: false}); + } Wait("stop"); }); diff --git a/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js b/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js index 9f639b2172..0cbf4e04b4 100644 --- a/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js +++ b/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js @@ -99,8 +99,7 @@ export default } }) .catch( (error) => { - console.log(error); - if (status_code === 403) { + if (error.status_code === 403) { /* user doesn't have access to see the project, no big deal. */ $scope.disablePlaybookBecausePermissionDenied = true; } else { @@ -144,9 +143,12 @@ export default .then(function(){ Wait('stop'); }) - .catch( (error) => { - console.log(error); - }) + .catch(({data, status}) => { + ProcessErrors($scope, data, status, null, { + hdr: 'Error!', + msg: 'Call failed. Returned status: ' + status + }); + }); } } }); diff --git a/awx/ui/client/src/templates/list/templates-list.controller.js b/awx/ui/client/src/templates/list/templates-list.controller.js index cce220f91c..b400ec66ed 100644 --- a/awx/ui/client/src/templates/list/templates-list.controller.js +++ b/awx/ui/client/src/templates/list/templates-list.controller.js @@ -210,13 +210,15 @@ export default ['$scope', '$rootScope', $state.go('templates.editJobTemplate', {job_template_id: results.id}, {reload: true}); } }) - .catch((error)=> { - console.log(error); - }) + .catch(({data, status}) => { + ProcessErrors($scope, data, status, null, { + hdr: 'Error!', + msg: 'Call failed. Return status: ' + status + }); + }); }) - .catch((error) => { - console.log(error); - ProcessErrors($rootScope, error, status, null, {hdr: 'Error!', + .catch(({data, status}) => { + ProcessErrors($rootScope, data, status, null, {hdr: 'Error!', msg: 'Call failed. Return status: '+ status}); }); }