You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sg...@apache.org on 2015/05/27 16:07:16 UTC
cordova-plugin-file-transfer git commit: CB-8951 (wp8) Handle
exceptions in download() and upload() again
Repository: cordova-plugin-file-transfer
Updated Branches:
refs/heads/master 72a5d951a -> ea225af6f
CB-8951 (wp8) Handle exceptions in download() and upload() again
github close #84
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/ea225af6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/ea225af6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/ea225af6
Branch: refs/heads/master
Commit: ea225af6f236793e7a14f80d8c37eda3c11e3a29
Parents: 72a5d95
Author: alsorokin <al...@akvelon.com>
Authored: Thu May 21 11:29:16 2015 +0300
Committer: sgrebnov <v-...@microsoft.com>
Committed: Wed May 27 17:06:59 2015 +0300
----------------------------------------------------------------------
src/wp/FileTransfer.cs | 43 ++++++++++++++++++++++++++++++-------------
1 file changed, 30 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/ea225af6/src/wp/FileTransfer.cs
----------------------------------------------------------------------
diff --git a/src/wp/FileTransfer.cs b/src/wp/FileTransfer.cs
index 675690f..0392d1c 100644
--- a/src/wp/FileTransfer.cs
+++ b/src/wp/FileTransfer.cs
@@ -334,7 +334,7 @@ namespace WPCordovaClassLib.Cordova.Commands
/// </summary>
/// <param name="options">Upload options</param>
/// exec(win, fail, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode, headers, this._id, httpMethod]);
- public async void upload(string options)
+ public void upload(string options)
{
options = options.Replace("{}", ""); // empty objects screw up the Deserializer
string callbackId = "";
@@ -398,9 +398,19 @@ namespace WPCordovaClassLib.Cordova.Commands
reqState.options = uploadOptions;
reqState.request = webRequest;
- // Associate cookies with the request
- // This is an async call, so we need to await it in order to preserve proper control flow
- await CopyCookiesFromWebBrowser(webRequest);
+ try
+ {
+ // Associate cookies with the request
+ // This is an async call, so we need to await it in order to preserve proper control flow
+ Task cookieTask = CopyCookiesFromWebBrowser(webRequest);
+ cookieTask.Wait();
+ }
+ catch (AggregateException ae)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR,
+ new FileTransferError(FileTransfer.ConnectionError, uploadOptions.FilePath, uploadOptions.Server, 0, ae.InnerException.Message)));
+ return;
+ }
if (!string.IsNullOrEmpty(uploadOptions.Headers))
{
@@ -445,7 +455,7 @@ namespace WPCordovaClassLib.Cordova.Commands
return new Dictionary<string, string>();
}
- public async void download(string options)
+ public void download(string options)
{
TransferOptions downloadOptions = null;
HttpWebRequest webRequest = null;
@@ -579,19 +589,26 @@ namespace WPCordovaClassLib.Cordova.Commands
state.request = webRequest;
InProcDownloads[downloadOptions.Id] = state;
- // Associate cookies with the request
- // This is an async call, so we need to await it in order to preserve proper control flow
- await CopyCookiesFromWebBrowser(webRequest);
+ try
+ {
+ // Associate cookies with the request
+ // This is an async call, so we need to await it in order to preserve proper control flow
+ Task cookieTask = CopyCookiesFromWebBrowser(webRequest);
+ cookieTask.Wait();
+ }
+ catch (AggregateException ae)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR,
+ new FileTransferError(FileTransfer.ConnectionError, downloadOptions.Url, downloadOptions.FilePath, 0, ae.InnerException.Message)));
+ return;
+ }
if (!string.IsNullOrEmpty(downloadOptions.Headers))
{
Dictionary<string, string> headers = parseHeaders(downloadOptions.Headers);
- if (headers != null)
+ foreach (string key in headers.Keys)
{
- foreach (string key in headers.Keys)
- {
- webRequest.Headers[key] = headers[key];
- }
+ webRequest.Headers[key] = headers[key];
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org