Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API (js) - handle non-2** (and 1**) responses as errors #783

Merged
merged 2 commits into from
Mar 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/assets/javascripts/miq_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,18 @@
}

function process_response(response) {
if (response.status === 204) // No content
if (response.status === 204) {
// No content
return null;
}

if (response.status >= 300) {
// Not 1** or 2**
return response.json()
.then(function(obj) {
return Promise.reject(obj);
});
}

return response.json();
}
Expand Down
7 changes: 5 additions & 2 deletions app/assets/javascripts/services/miq_service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global miqAjaxButton miqBuildCalendar miqButtons miqJqueryRequest miqRESTAjaxButton miqSparkleOff miqSparkleOn */

ManageIQ.angular.app.service('miqService', ['$timeout', '$document', '$q', '$log', function($timeout, $document, $q, $log) {
ManageIQ.angular.app.service('miqService', ['$timeout', '$document', '$q', function($timeout, $document, $q) {
this.storedPasswordPlaceholder = "●●●●●●●●";

this.showButtons = function() {
Expand Down Expand Up @@ -124,11 +124,14 @@ ManageIQ.angular.app.service('miqService', ['$timeout', '$document', '$q', '$log

return serializedObj;
};

this.handleFailure = function(e) {
miqSparkleOff();

if (e.message) {
$log.log(e.message);
console.error(e.message);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reason to remove $log here.

How about using $log.error() instead of console.error (will also take care of the CC error)

Copy link
Contributor Author

@himdel himdel Mar 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like $log doesn't seem to work together with out toast-errors-in-devel-mode code :(.

And since we're not using $log anywhere else, I see no reason to fix that... do you?

EDIT: also, the point of CC warning about console.* is not to never use console.*, but to only use it in cases where console output is desired, as opposed to leaving debugging code in, or pretending to notify users by doing console.*. So... using $log instead of console just to prevent CC errors would be exactly the wrong solution. (And yes, we should add a CC warning about $log as well.)


return $q.reject(e);
};
}]);