| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * Simple utilities for making XHRs more pleasant. | 7 * Simple utilities for making XHRs more pleasant. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 192 } |
| 193 xhr.withCredentials = withCredentials; | 193 xhr.withCredentials = withCredentials; |
| 194 xhr.send(content); | 194 xhr.send(content); |
| 195 return xhr; | 195 return xhr; |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 /** | 198 /** |
| 199 * Generic success/failure response proxy. | 199 * Generic success/failure response proxy. |
| 200 * | 200 * |
| 201 * @param {function():void} onDone | 201 * @param {function():void} onDone |
| 202 * @param {function(remoting.Error):void} onError | 202 * @param {function(!remoting.Error):void} onError |
| 203 * @return {function(XMLHttpRequest):void} | 203 * @return {function(XMLHttpRequest):void} |
| 204 */ | 204 */ |
| 205 remoting.xhr.defaultResponse = function(onDone, onError) { | 205 remoting.xhr.defaultResponse = function(onDone, onError) { |
| 206 /** @param {XMLHttpRequest} xhr */ | 206 /** @param {XMLHttpRequest} xhr */ |
| 207 var result = function(xhr) { | 207 var result = function(xhr) { |
| 208 /** @type {remoting.Error} */ | |
| 209 var error = | 208 var error = |
| 210 remoting.Error.fromHttpStatus(/** @type {number} */ (xhr.status)); | 209 remoting.Error.fromHttpStatus(/** @type {number} */ (xhr.status)); |
| 211 if (error == remoting.Error.NONE) { | 210 if (error.tag == remoting.Error.Tag.NONE) { |
| 212 onDone(); | 211 onDone(); |
| 213 } else { | 212 } else { |
| 214 onError(error); | 213 onError(error); |
| 215 } | 214 } |
| 216 }; | 215 }; |
| 217 return result; | 216 return result; |
| 218 }; | 217 }; |
| OLD | NEW |