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

Side by Side Diff: remoting/webapp/crd/js/it2me_connect_flow.js

Issue 1004513002: Eliminated named constants for instances of remoting.Error. (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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 /** @suppress {duplicate} */ 5 /** @suppress {duplicate} */
6 var remoting = remoting || {}; 6 var remoting = remoting || {};
7 7
8 (function() { 8 (function() {
9 9
10 'use strict'; 10 'use strict';
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 }; 67 };
68 68
69 /** 69 /**
70 * @param {string} accessCode 70 * @param {string} accessCode
71 * @return {Promise} Promise that resolves if the access code is valid. 71 * @return {Promise} Promise that resolves if the access code is valid.
72 * @private 72 * @private
73 */ 73 */
74 remoting.It2MeConnectFlow.prototype.verifyAccessCode_ = function(accessCode) { 74 remoting.It2MeConnectFlow.prototype.verifyAccessCode_ = function(accessCode) {
75 var normalizedAccessCode = accessCode.replace(/\s/g, ''); 75 var normalizedAccessCode = accessCode.replace(/\s/g, '');
76 if (normalizedAccessCode.length !== ACCESS_CODE_LENGTH) { 76 if (normalizedAccessCode.length !== ACCESS_CODE_LENGTH) {
77 return Promise.reject(remoting.Error.INVALID_ACCESS_CODE); 77 return Promise.reject(new remoting.Error(
78 remoting.Error.Tag.INVALID_ACCESS_CODE));
78 } 79 }
79 80
80 this.hostId_ = normalizedAccessCode.substring(0, SUPPORT_ID_LENGTH); 81 this.hostId_ = normalizedAccessCode.substring(0, SUPPORT_ID_LENGTH);
81 this.passCode_ = normalizedAccessCode; 82 this.passCode_ = normalizedAccessCode;
82 83
83 return Promise.resolve(); 84 return Promise.resolve();
84 }; 85 };
85 86
86 /** 87 /**
87 * Continues an IT2Me connection once an access token has been obtained. 88 * Continues an IT2Me connection once an access token has been obtained.
(...skipping 29 matching lines...) Expand all
117 if (response && response.data && 118 if (response && response.data &&
118 response.data.jabberId && response.data.publicKey) { 119 response.data.jabberId && response.data.publicKey) {
119 var host = new remoting.Host(); 120 var host = new remoting.Host();
120 host.hostId = this.hostId_; 121 host.hostId = this.hostId_;
121 host.jabberId = response.data.jabberId; 122 host.jabberId = response.data.jabberId;
122 host.publicKey = response.data.publicKey; 123 host.publicKey = response.data.publicKey;
123 host.hostName = response.data.jabberId.split('/')[0]; 124 host.hostName = response.data.jabberId.split('/')[0];
124 return Promise.resolve(host); 125 return Promise.resolve(host);
125 } else { 126 } else {
126 console.error('Invalid "support-hosts" response from server.'); 127 console.error('Invalid "support-hosts" response from server.');
127 return Promise.reject(remoting.Error.UNEXPECTED); 128 return Promise.reject(remoting.Error.unexpected());
128 } 129 }
129 } else { 130 } else {
130 return Promise.reject(translateSupportHostsError(xhr.status)); 131 return Promise.reject(translateSupportHostsError(xhr.status));
131 } 132 }
132 }; 133 };
133 134
134 /** 135 /**
135 * @param {number} error An HTTP error code returned by the support-hosts 136 * @param {number} error An HTTP error code returned by the support-hosts
136 * endpoint. 137 * endpoint.
137 * @return {remoting.Error} The equivalent remoting.Error code. 138 * @return {remoting.Error} The equivalent remoting.Error code.
138 */ 139 */
139 function translateSupportHostsError(error) { 140 function translateSupportHostsError(error) {
140 switch (error) { 141 switch (error) {
141 case 0: return remoting.Error.NETWORK_FAILURE; 142 case 0: return new remoting.Error(remoting.Error.Tag.NETWORK_FAILURE);
142 case 404: return remoting.Error.INVALID_ACCESS_CODE; 143 case 404: return new remoting.Error(remoting.Error.Tag.INVALID_ACCESS_CODE);
143 case 502: // No break 144 case 502: // No break
144 case 503: return remoting.Error.SERVICE_UNAVAILABLE; 145 case 503: return new remoting.Error(remoting.Error.Tag.SERVICE_UNAVAILABLE);
145 default: return remoting.Error.UNEXPECTED; 146 default: return remoting.Error.unexpected();
146 } 147 }
147 } 148 }
148 149
149 })(); 150 })();
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/host_setup_dialog.js ('k') | remoting/webapp/crd/js/it2me_host_facade.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698