Chromium Code Reviews| 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 19 matching lines...) Expand all Loading... | |
| 30 remoting.Error.prototype.toString = function() { | 30 remoting.Error.prototype.toString = function() { |
| 31 var result = this.tag_; | 31 var result = this.tag_; |
| 32 if (this.detail_ != null) { | 32 if (this.detail_ != null) { |
| 33 result += ' (' + this.detail_ + ')'; | 33 result += ' (' + this.detail_ + ')'; |
| 34 } | 34 } |
| 35 return result; | 35 return result; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * @return {remoting.ChromotingEvent.ConnectionError} error | 39 * @return {remoting.ChromotingEvent.ConnectionError} error |
| 40 * | |
| 41 * @private | |
| 40 */ | 42 */ |
| 41 remoting.Error.prototype.toConnectionError = function() { | 43 remoting.Error.prototype.toConnectionError_ = function() { |
| 42 var Tag = remoting.Error.Tag; | 44 var Tag = remoting.Error.Tag; |
| 43 var ConnectionError = remoting.ChromotingEvent.ConnectionError; | 45 var ConnectionError = remoting.ChromotingEvent.ConnectionError; |
| 44 switch (this.tag_) { | 46 switch (this.tag_) { |
| 45 case Tag.NONE: | 47 case Tag.NONE: |
| 46 return ConnectionError.NONE; | 48 return ConnectionError.NONE; |
| 47 case Tag.CLIENT_SUSPENDED: | 49 case Tag.CLIENT_SUSPENDED: |
| 48 return ConnectionError.CLIENT_SUSPENDED; | 50 return ConnectionError.CLIENT_SUSPENDED; |
| 49 case Tag.INVALID_ACCESS_CODE: | 51 case Tag.INVALID_ACCESS_CODE: |
| 50 return ConnectionError.INVALID_ACCESS_CODE; | 52 return ConnectionError.INVALID_ACCESS_CODE; |
| 51 case Tag.MISSING_PLUGIN: | 53 case Tag.MISSING_PLUGIN: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 }; | 97 }; |
| 96 | 98 |
| 97 /** | 99 /** |
| 98 * @return {?string} The detail string passed to the constructor, if any. | 100 * @return {?string} The detail string passed to the constructor, if any. |
| 99 */ | 101 */ |
| 100 remoting.Error.prototype.getDetail = function() { | 102 remoting.Error.prototype.getDetail = function() { |
| 101 return this.detail_; | 103 return this.detail_; |
| 102 }; | 104 }; |
| 103 | 105 |
| 104 /** | 106 /** |
| 107 * Populates the corresponding field in the |logEntry| based on the error tag. | |
| 108 * | |
| 109 * @param {remoting.ChromotingEvent} logEntry | |
| 110 */ | |
| 111 remoting.Error.prototype.fillLogEntry = function(logEntry) { | |
| 112 logEntry.connection_error = this.toConnectionError_(); | |
| 113 | |
| 114 var Tag = remoting.Error.Tag; | |
| 115 var detail = /** @type{string} */ (this.getDetail()); | |
|
kelvinp
2015/11/07 04:44:11
This extra variable is needed to cast getDetail()
Jamie
2015/11/09 18:46:02
Nit: Space after "@type"
kelvinp
2015/11/09 22:59:10
Done.
| |
| 116 | |
| 117 switch (this.tag_) { | |
| 118 case Tag.HOST_IS_OFFLINE: | |
| 119 if (detail) { | |
| 120 logEntry.xmpp_error = new remoting.ChromotingEvent.XmppError(detail); | |
| 121 } | |
| 122 break; | |
| 123 case Tag.MISSING_PLUGIN: | |
| 124 console.assert(detail, 'Missing PNaCl plugin last error string.'); | |
| 125 logEntry.raw_plugin_error = detail; | |
| 126 } | |
| 127 }; | |
| 128 | |
| 129 /** | |
| 105 * Checks the type of an error. | 130 * Checks the type of an error. |
| 106 * @param {remoting.Error.Tag} tag | 131 * @param {remoting.Error.Tag} tag |
| 107 * @param {...remoting.Error.Tag} var_args | 132 * @param {...remoting.Error.Tag} var_args |
| 108 * @return {boolean} True if this object has one of the specified tags. | 133 * @return {boolean} True if this object has one of the specified tags. |
| 109 * @suppress {reportUnknownTypes} | 134 * @suppress {reportUnknownTypes} |
| 110 */ | 135 */ |
| 111 remoting.Error.prototype.hasTag = function(tag, var_args) { | 136 remoting.Error.prototype.hasTag = function(tag, var_args) { |
| 112 var thisTag = this.tag_; | 137 var thisTag = this.tag_; |
| 113 return Array.prototype.some.call( | 138 return Array.prototype.some.call( |
| 114 arguments, | 139 arguments, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 remoting.Error.handler = function(onError) { | 254 remoting.Error.handler = function(onError) { |
| 230 return function(/** * */ error) { | 255 return function(/** * */ error) { |
| 231 if (error instanceof remoting.Error) { | 256 if (error instanceof remoting.Error) { |
| 232 onError(/** @type {!remoting.Error} */ (error)); | 257 onError(/** @type {!remoting.Error} */ (error)); |
| 233 } else { | 258 } else { |
| 234 console.error('Unexpected error:', error); | 259 console.error('Unexpected error:', error); |
| 235 onError(remoting.Error.unexpected()); | 260 onError(remoting.Error.unexpected()); |
| 236 } | 261 } |
| 237 }; | 262 }; |
| 238 }; | 263 }; |
| OLD | NEW |