more tweaks to error handling · 725b6e1dca - SVN.BY: Go Git Service
瀏覽代碼

more tweaks to error handling

Related Work Items: #25
Tiernan OToole 8 年之前
父節點
當前提交
725b6e1dca
共有 1 個文件被更改,包括 12 次插入2 次删除
  1. 12 2
      B2Uploader/Program.cs

+ 12 - 2
B2Uploader/Program.cs

167
 
167
 
168
         static string MakeWebRequest<T>(string url, List<Tuple<string,string>> headers, T item, string contentType = "application/json; charset=utf-8")
168
         static string MakeWebRequest<T>(string url, List<Tuple<string,string>> headers, T item, string contentType = "application/json; charset=utf-8")
169
         {
169
         {
170
+            string body = string.Empty;
171
+             byte[] data;
170
             try
172
             try
171
             {
173
             {
172
                 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
174
                 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
173
-                byte[] data;
175
+               
174
 
176
 
175
                 if (typeof(T) == typeof(byte[]))
177
                 if (typeof(T) == typeof(byte[]))
176
                 {
178
                 {
178
                 }
180
                 }
179
                 else
181
                 else
180
                 {
182
                 {
181
-                    string body = JsonConvert.SerializeObject(item);
183
+                    body =  JsonConvert.SerializeObject(item);
182
 
184
 
183
                     data = Encoding.UTF8.GetBytes(body);
185
                     data = Encoding.UTF8.GetBytes(body);
184
                 }
186
                 }
207
             {
209
             {
208
                 Console.WriteLine("Error talking to server: {0}", ex.Message);
210
                 Console.WriteLine("Error talking to server: {0}", ex.Message);
209
                 Console.WriteLine("URL: {0}", url);
211
                 Console.WriteLine("URL: {0}", url);
212
+                if (string.IsNullOrWhiteSpace(body))
213
+                {
214
+                    Console.WriteLine("Byte array sent in... ");
215
+                }
216
+                else
217
+                {
218
+                    Console.WriteLine("Body: {0}", body);
219
+                }
210
                 throw;
220
                 throw;
211
             }
221
             }
212
 
222