@@ -389,19 +389,26 @@ namespace {{packageName}}.Client
389389 HttpWebResponse responseT = (HttpWebResponse)requestT.GetResponse();
390390 using (Stream responseStream = responseT.GetResponseStream())
391391 {
392- //setting high timeout to accomodate large files till 2GB, need to revisit for a dynamic approach
393- responseStream.ReadTimeout = 8000000;
394- responseStream.WriteTimeout = 9000000;
395- using (Stream fileStream = File.OpenWrite(@DownloadReponseFileName))
392+ try
396393 {
397- byte[] buffer = new byte[4096];
398- int bytesRead = responseStream.Read(buffer, 0, 4096);
399- while (bytesRead > 0)
394+ //setting high timeout to accomodate large files till 2GB, need to revisit for a dynamic approach
395+ responseStream.ReadTimeout = 8000000;
396+ responseStream.WriteTimeout = 9000000;
397+ using (Stream fileStream = File.OpenWrite(@DownloadReponseFileName))
400398 {
401- fileStream.Write(buffer, 0, bytesRead);
402- bytesRead = responseStream.Read(buffer, 0, 4096);
399+ byte[] buffer = new byte[4096];
400+ int bytesRead = responseStream.Read(buffer, 0, 4096);
401+ while (bytesRead > 0)
402+ {
403+ fileStream.Write(buffer, 0, bytesRead);
404+ bytesRead = responseStream.Read(buffer, 0, 4096);
405+ }
403406 }
404407 }
408+ catch (Exception)
409+ {
410+ throw new ApiException(-1, $" Error writing to path : {DownloadReponseFileName}" );
411+ }
405412 }
406413
407414 //setting the generic response with response headers
@@ -825,11 +832,11 @@ namespace {{packageName}}.Client
825832 int proxyPortTest;
826833
827834 if (! string.IsNullOrWhiteSpace(merchantConfig.ProxyAddress) && int.TryParse(merchantConfig.ProxyPort, out proxyPortTest))
828- {
835+ {
829836 WebProxy proxy = new WebProxy(merchantConfig.ProxyAddress, proxyPortTest);
830837
831838 if (! string.IsNullOrWhiteSpace(merchantConfig.ProxyUsername) && ! string.IsNullOrWhiteSpace(merchantConfig.ProxyPassword))
832- {
839+ {
833840 proxy.Credentials = new NetworkCredential(merchantConfig.ProxyUsername, merchantConfig.ProxyPassword);
834841 }
835842
0 commit comments