Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Unified Diff: remoting/webapp/crd/js/host_list_api_impl.js

Issue 1028683004: Added better error and OAuth support in xhr.js. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/app_remoting_webapp_files.gypi ('k') | remoting/webapp/crd/js/xhr.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/crd/js/host_list_api_impl.js
diff --git a/remoting/webapp/crd/js/host_list_api_impl.js b/remoting/webapp/crd/js/host_list_api_impl.js
index 52f9377e58a12aa64aa256b4094b69d3cc5397b7..99007defdccf20312cb4f3e2c802438c7813ce11 100644
--- a/remoting/webapp/crd/js/host_list_api_impl.js
+++ b/remoting/webapp/crd/js/host_list_api_impl.js
@@ -67,7 +67,7 @@ remoting.HostListApiImpl.prototype.put =
url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId,
jsonContent: newHostDetails,
oauthToken: token
- }).start().then(remoting.Xhr.defaultResponse(onDone, onError));
+ }).start().then(remoting.HostListApiImpl.defaultResponse_(onDone, onError));
};
remoting.identity.getToken().then(onToken, remoting.Error.handler(onError));
Jamie 2015/03/24 19:44:11 Why have you reverted the useIdentity change as we
John Williams 2015/03/24 23:34:41 Accident.
};
@@ -86,7 +86,7 @@ remoting.HostListApiImpl.prototype.remove = function(hostId, onDone, onError) {
method: 'DELETE',
url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId,
oauthToken: token
- }).start().then(remoting.Xhr.defaultResponse(
+ }).start().then(remoting.HostListApiImpl.defaultResponse_(
onDone, onError, [remoting.Error.Tag.NOT_FOUND]));
};
remoting.identity.getToken().then(onToken, remoting.Error.handler(onError));
@@ -135,6 +135,35 @@ remoting.HostListApiImpl.prototype.parseHostListResponse_ =
}
};
+/**
+ * Generic success/failure response proxy.
+ *
+ * @param {function():void} onDone
+ * @param {function(!remoting.Error):void} onError
+ * @param {Array<remoting.Error.Tag>=} opt_ignoreErrors
+ * @return {function(!remoting.Xhr.Response):void}
+ * @private
+ */
+remoting.HostListApiImpl.defaultResponse_ = function(
+ onDone, onError, opt_ignoreErrors) {
+ /** @param {!remoting.Xhr.Response} response */
+ var result = function(response) {
+ var error = remoting.Error.fromHttpStatus(response.status);
+ if (error.isNone()) {
+ onDone();
+ return;
+ }
+
+ if (opt_ignoreErrors && error.hasTag.apply(error, opt_ignoreErrors)) {
+ onDone();
+ return;
+ }
+
+ onError(error);
+ };
+ return result;
+};
+
/** @type {remoting.HostListApi} */
remoting.hostListApi = new remoting.HostListApiImpl();
« no previous file with comments | « remoting/app_remoting_webapp_files.gypi ('k') | remoting/webapp/crd/js/xhr.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698