Skip to content

Commit

Permalink
Fixed Error handling of REST API calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
h-kataria committed Feb 27, 2017
1 parent ef884b3 commit 04a2c53
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions app/assets/javascripts/services/post_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ ManageIQ.angular.app.service('postService', ["miqService", "$timeout", "$window"
angular.toJson({
action: "edit",
resource: updateObject
})).then(handleSuccess, handleFailure);
})).then(function(response) {
if (response.error) {
handleFailure(response);
} else {
handleSuccess;
}
});

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

function handleFailure(response) {
var msg = sprintf(__("Error during Save: [%s - %s]"), response.status, response.responseText);
$timeout(function () {
$window.location.href = redirectURL + '&flash_msg=' + msg + '&flash_error=true';
var msg = sprintf(__('Error during Save: [%s - %s]'), response.error.klass, response.error.message);
$timeout(function() {
miqService.sparkleOff();
miqService.miqFlash('error', __(msg));
});
}
};
Expand All @@ -28,18 +35,25 @@ ManageIQ.angular.app.service('postService', ["miqService", "$timeout", "$window"
angular.toJson({
action: "create",
resource: createObject
})).then(handleSuccess, handleFailure);
})).then(function(response) {
if (response.error) {
handleFailure(response);
} else {
handleSuccess;
}
});

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

function handleFailure(response) {
var msg = sprintf(__("Error during Add: [%s - %s]"), response.status, response.responseText);
$timeout(function () {
$window.location.href = redirectURL + '&flash_msg=' + msg + '&flash_error=true';
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 04a2c53

Please sign in to comment.