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

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

Issue 937593002: Changed identity API to use promises instead of callbacks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed bad merge Created 5 years, 10 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/webapp/crd/js/crd_event_handlers.js ('k') | remoting/webapp/crd/js/hangout_consent_dialog.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/crd/js/error.js
diff --git a/remoting/webapp/crd/js/error.js b/remoting/webapp/crd/js/error.js
index 3001f9a95ccb6546fc4f3582ca0b0bdf7e4f4b4c..c3e439195315f661181b173c9cef8eaab44c9781 100644
--- a/remoting/webapp/crd/js/error.js
+++ b/remoting/webapp/crd/js/error.js
@@ -61,3 +61,65 @@ remoting.Error.fromHttpStatus = function(httpStatus) {
return remoting.Error.AUTHENTICATION_FAILED;
}
};
+
+/**
+ * Create an error-handling function suitable for passing to a
+ * Promise's "catch" method.
+ *
+ * @param {function(remoting.Error):void} onError
+ * @return {function(*):void}
+ */
+remoting.Error.handler = function(onError) {
+ return function(/** * */ error) {
+ if (typeof error == 'string') {
+ onError(/** @type {remoting.Error} */ (error));
+ } else {
+ console.error('Unexpected error: %o', error);
+ onError(remoting.Error.UNEXPECTED);
+ }
+ };
+};
+
+// /**
+// * @param {(!Promise<T>|
+// * function(function(T):void,function(remoting.Error):void))} arg
+// * @constructor
+// * @template T
+// */
+// remoting.Promise = function(arg) {
+// var promise;
+// if (typeof arg == 'function') {
+// promise = new Promise(arg);
+// } else {
+// promise = arg;
+// }
+
+// /** @const */
+// this.promise = promise;
+// };
+
+// /**
+// * @param {?function(T)} onResolve
+// * @param {?function(remoting.Error)=} opt_onReject
+// * @return {!remoting.Promise}
+// */
+// remoting.Promise.prototype.then = function(onResolve, opt_onReject) {
+// return new remoting.Promise(this.promise.then(
+// onResolve,
+// opt_onReject && function(/** * */ error) {
+// if (typeof error == 'string') {
+// opt_onReject(/** @type {remoting.Error} */ (error));
+// } else {
+// console.error('Unexpected error: %o', error);
+// opt_onReject(remoting.Error.UNEXPECTED);
+// }
+// }));
+// };
+
+// /**
+// * @param {?function(remoting.Error)} onReject
+// * @return {!remoting.Promise<T>}
+// */
+// remoting.Promise.prototype.catch = function(onReject) {
+// return this.then(null, onReject);
+// };
« no previous file with comments | « remoting/webapp/crd/js/crd_event_handlers.js ('k') | remoting/webapp/crd/js/hangout_consent_dialog.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698