Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 7ea50e5

Browse files
Detecting errors properly when downloading
1 parent 122abe0 commit 7ea50e5

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/GitHub.Api/Tasks/DownloadTask.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ public static WebResponse GetResponseWithoutException(this WebRequest request)
8585
}
8686
catch (WebException e)
8787
{
88-
return e.Response;
88+
if (e.Response != null)
89+
{
90+
return e.Response;
91+
}
92+
93+
throw e;
8994
}
9095
}
9196
}

src/tests/IntegrationTests/Download/DownloadTaskTests.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public void TestDownloadFailure()
8181
exceptionThrown.Should().NotBeNull();
8282
}
8383

84-
8584
[Test]
8685
public void TestDownloadTextTask()
8786
{
@@ -92,6 +91,26 @@ public void TestDownloadTextTask()
9291
var resultLines = result.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
9392
resultLines[0].Should().Be("# If you would like to crawl GitHub contact us at [email protected].");
9493
}
94+
95+
[Test]
96+
public void TestDownloadTextFailture()
97+
{
98+
InitializeTaskManager();
99+
100+
var downloadTask = new DownloadTextTask(CancellationToken.None, "https://ggggithub.com/robots.txt");
101+
var exceptionThrown = false;
102+
103+
try
104+
{
105+
var result = downloadTask.Start().Result;
106+
}
107+
catch (Exception e)
108+
{
109+
exceptionThrown = true;
110+
}
111+
112+
exceptionThrown.Should().BeTrue();
113+
}
95114

96115
[Test]
97116
public void TestDownloadFileAndHash()

0 commit comments

Comments
 (0)