Skip to content

Commit

Permalink
made changes to code to handle API Failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
h-kataria committed Mar 5, 2017
1 parent 6f29c20 commit b36de98
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/services/miq_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ ManageIQ.angular.app.service('miqService', ['$timeout', '$document', '$q', '$log

return serializedObj;
};

this.handleFailure = function(e) {
miqSparkleOff();
if (e.message) {
Expand Down
50 changes: 18 additions & 32 deletions app/assets/javascripts/services/post_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,19 @@ ManageIQ.angular.app.service('postService', ["miqService", "$timeout", "$window"
angular.toJson({
action: "edit",
resource: updateObject
})).then(function(response) {
})).then(handleSuccess)
.catch(miqService.handleFailure);

function handleSuccess(response) {
$timeout(function () {
if (response.error) {
handleFailure(response);
var msg = __(response.error.klass + ': ' + response.error.message);
miqService.miqFlash('error', msg);
miqService.sparkleOff();
} else {
handleSuccess;
$window.location.href = redirectURL + '&flash_msg=' + successMsg;
}
});

function handleSuccess() {
$timeout(function () {
$window.location.href = redirectURL + '&flash_msg=' + successMsg;
});
}

function handleFailure(response) {
var msg = sprintf(__('Error during Save: [%s - %s]'), response.error.klass, response.error.message);
$timeout(function() {
miqService.sparkleOff();
miqService.miqFlash('error', __(msg));
});
}
};

Expand All @@ -35,26 +28,19 @@ ManageIQ.angular.app.service('postService', ["miqService", "$timeout", "$window"
angular.toJson({
action: "create",
resource: createObject
})).then(function(response) {
})).then(handleSuccess)
.catch(miqService.handleFailure);

function handleSuccess(response) {
$timeout(function () {
if (response.error) {
handleFailure(response);
var msg = __(response.error.klass + ': ' + response.error.message);
miqService.miqFlash('error', msg);
miqService.sparkleOff();
} else {
handleSuccess;
$window.location.href = redirectURL + '&flash_msg=' + successMsg;
}
});

function handleSuccess() {
$timeout(function () {
$window.location.href = redirectURL + '&flash_msg=' + successMsg;
});
}

function handleFailure(response) {
var msg = sprintf(__('Error during Add: [%s - %s]'), response.error.klass, response.error.message);
$timeout(function() {
miqService.sparkleOff();
miqService.miqFlash('error', __(msg));
});
}
};

Expand Down

0 comments on commit b36de98

Please sign in to comment.