| 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 18 matching lines...) Expand all Loading... |
| 29 UNEXPECTED: /*i18n-content*/'ERROR_UNEXPECTED', | 29 UNEXPECTED: /*i18n-content*/'ERROR_UNEXPECTED', |
| 30 SERVICE_UNAVAILABLE: /*i18n-content*/'ERROR_SERVICE_UNAVAILABLE', | 30 SERVICE_UNAVAILABLE: /*i18n-content*/'ERROR_SERVICE_UNAVAILABLE', |
| 31 NOT_AUTHENTICATED: /*i18n-content*/'ERROR_NOT_AUTHENTICATED', | 31 NOT_AUTHENTICATED: /*i18n-content*/'ERROR_NOT_AUTHENTICATED', |
| 32 INVALID_HOST_DOMAIN: /*i18n-content*/'ERROR_INVALID_HOST_DOMAIN', | 32 INVALID_HOST_DOMAIN: /*i18n-content*/'ERROR_INVALID_HOST_DOMAIN', |
| 33 P2P_FAILURE: /*i18n-content*/'ERROR_P2P_FAILURE', | 33 P2P_FAILURE: /*i18n-content*/'ERROR_P2P_FAILURE', |
| 34 REGISTRATION_FAILED: /*i18n-content*/'ERROR_HOST_REGISTRATION_FAILED', | 34 REGISTRATION_FAILED: /*i18n-content*/'ERROR_HOST_REGISTRATION_FAILED', |
| 35 NOT_AUTHORIZED: /*i18n-content*/'ERROR_NOT_AUTHORIZED' | 35 NOT_AUTHORIZED: /*i18n-content*/'ERROR_NOT_AUTHORIZED' |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * @param {number} httpError An HTTP error code. | 39 * @param {number} httpStatus An HTTP status code. |
| 40 * @return {remoting.Error} The remoting.Error enum corresponding to the | 40 * @return {remoting.Error} The remoting.Error enum corresponding to the |
| 41 * specified HTTP error code. | 41 * specified HTTP status code. |
| 42 */ | 42 */ |
| 43 remoting.Error.fromHttpError = function(httpError) { | 43 remoting.Error.fromHttpStatus = function(httpStatus) { |
| 44 if (httpError == 0) { | 44 if (httpStatus == 0) { |
| 45 return remoting.Error.NETWORK_FAILURE; | 45 return remoting.Error.NETWORK_FAILURE; |
| 46 } else if (httpError == 200) { | 46 } else if (httpStatus >= 200 && httpStatus < 300) { |
| 47 return remoting.Error.NONE; | 47 return remoting.Error.NONE; |
| 48 } else if (httpError == 400 || httpError == 401) { | 48 } else if (httpStatus == 400 || httpStatus == 401) { |
| 49 return remoting.Error.AUTHENTICATION_FAILED; | 49 return remoting.Error.AUTHENTICATION_FAILED; |
| 50 } else if (httpError >= 500 && httpError < 600) { | 50 } else if (httpStatus >= 500 && httpStatus < 600) { |
| 51 return remoting.Error.SERVICE_UNAVAILABLE; | 51 return remoting.Error.SERVICE_UNAVAILABLE; |
| 52 } else { | 52 } else { |
| 53 console.warn('Unexpected HTTP error code: ' + httpError); | 53 console.warn('Unexpected HTTP error code: ' + httpStatus); |
| 54 // Return AUTHENTICATION_FAILED by default, so that the user can try to | 54 // Return AUTHENTICATION_FAILED by default, so that the user can try to |
| 55 // recover from an unexpected failure by signing in again. | 55 // recover from an unexpected failure by signing in again. |
| 56 // TODO(jamiewalch): Return UNEXPECTED here and let calling code treat that | 56 // TODO(jamiewalch): Return UNEXPECTED here and let calling code treat that |
| 57 // as "sign-in required" if necessary. | 57 // as "sign-in required" if necessary. |
| 58 return remoting.Error.AUTHENTICATION_FAILED; | 58 return remoting.Error.AUTHENTICATION_FAILED; |
| 59 } | 59 } |
| 60 }; | 60 }; |
| OLD | NEW |