OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
9 | 9 |
10 /** | 10 /** |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 return remoting.Error.SERVICE_UNAVAILABLE; | 54 return remoting.Error.SERVICE_UNAVAILABLE; |
55 } else { | 55 } else { |
56 console.warn('Unexpected HTTP error code: ' + httpStatus); | 56 console.warn('Unexpected HTTP error code: ' + httpStatus); |
57 // Return AUTHENTICATION_FAILED by default, so that the user can try to | 57 // Return AUTHENTICATION_FAILED by default, so that the user can try to |
58 // recover from an unexpected failure by signing in again. | 58 // recover from an unexpected failure by signing in again. |
59 // TODO(jamiewalch): Return UNEXPECTED here and let calling code treat that | 59 // TODO(jamiewalch): Return UNEXPECTED here and let calling code treat that |
60 // as "sign-in required" if necessary. | 60 // as "sign-in required" if necessary. |
61 return remoting.Error.AUTHENTICATION_FAILED; | 61 return remoting.Error.AUTHENTICATION_FAILED; |
62 } | 62 } |
63 }; | 63 }; |
| 64 |
| 65 /** |
| 66 * Create an error-handling function suitable for passing to a |
| 67 * Promise's "catch" method. |
| 68 * |
| 69 * @param {function(remoting.Error):void} onError |
| 70 * @return {function(*):void} |
| 71 */ |
| 72 remoting.Error.handler = function(onError) { |
| 73 return function(/** * */ error) { |
| 74 if (typeof error == 'string') { |
| 75 onError(/** @type {remoting.Error} */ (error)); |
| 76 } else { |
| 77 console.error('Unexpected error: %o', error); |
| 78 onError(remoting.Error.UNEXPECTED); |
| 79 } |
| 80 }; |
| 81 }; |
| 82 |
| 83 // /** |
| 84 // * @param {(!Promise<T>| |
| 85 // * function(function(T):void,function(remoting.Error):void))} arg |
| 86 // * @constructor |
| 87 // * @template T |
| 88 // */ |
| 89 // remoting.Promise = function(arg) { |
| 90 // var promise; |
| 91 // if (typeof arg == 'function') { |
| 92 // promise = new Promise(arg); |
| 93 // } else { |
| 94 // promise = arg; |
| 95 // } |
| 96 |
| 97 // /** @const */ |
| 98 // this.promise = promise; |
| 99 // }; |
| 100 |
| 101 // /** |
| 102 // * @param {?function(T)} onResolve |
| 103 // * @param {?function(remoting.Error)=} opt_onReject |
| 104 // * @return {!remoting.Promise} |
| 105 // */ |
| 106 // remoting.Promise.prototype.then = function(onResolve, opt_onReject) { |
| 107 // return new remoting.Promise(this.promise.then( |
| 108 // onResolve, |
| 109 // opt_onReject && function(/** * */ error) { |
| 110 // if (typeof error == 'string') { |
| 111 // opt_onReject(/** @type {remoting.Error} */ (error)); |
| 112 // } else { |
| 113 // console.error('Unexpected error: %o', error); |
| 114 // opt_onReject(remoting.Error.UNEXPECTED); |
| 115 // } |
| 116 // })); |
| 117 // }; |
| 118 |
| 119 // /** |
| 120 // * @param {?function(remoting.Error)} onReject |
| 121 // * @return {!remoting.Promise<T>} |
| 122 // */ |
| 123 // remoting.Promise.prototype.catch = function(onReject) { |
| 124 // return this.then(null, onReject); |
| 125 // }; |
OLD | NEW |