Move error handling to Connection

The adapter shouldn't be responsible for translating errors
into the proper exception.
This commit is contained in:
Haacked
2013-09-30 10:45:03 -07:00
parent a8a5249726
commit 372fd25914
4 changed files with 53 additions and 36 deletions
+6 -11
View File
@@ -1,6 +1,5 @@
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
@@ -26,10 +25,11 @@ namespace Octokit.Http
{
Ensure.ArgumentNotNull(responseMessage, "responseMessage");
string responseBody = await responseMessage
.EnsureSuccess()
.Content
.ReadAsStringAsync();
var completedResponse = responseMessage.EnsureSuccess();
string responseBody = completedResponse != null
? await completedResponse.Content.ReadAsStringAsync()
: null;
var response = new ApiResponse<T>
{
@@ -88,12 +88,7 @@ namespace Octokit.Http
content.Dispose();
}
if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.Forbidden)
throw new AuthenticationException("You must be authenticated to call this method. Either supply a " +
"login/password or an oauth token.", response.StatusCode);
// TODO: Flesh this out.
throw new HttpRequestException("Unknown exception occurred.");
return null;
}
}
}