diff --git a/Octokit/Exceptions/ApiException.cs b/Octokit/Exceptions/ApiException.cs
index 97c7a809..9e16c540 100644
--- a/Octokit/Exceptions/ApiException.cs
+++ b/Octokit/Exceptions/ApiException.cs
@@ -32,7 +32,7 @@ namespace Octokit
/// The error message
/// The HTTP status code from the response
public ApiException(string message, HttpStatusCode httpStatusCode)
- : this(new Response {Body = message, StatusCode = httpStatusCode})
+ : this(GetApiErrorFromExceptionMessage(message), httpStatusCode, null)
{
}
@@ -42,7 +42,7 @@ namespace Octokit
/// The error message
/// The inner exception
public ApiException(string message, Exception innerException)
- : this(new Response { Body = message }, innerException)
+ : this(GetApiErrorFromExceptionMessage(message), 0, innerException)
{
}
@@ -76,10 +76,27 @@ namespace Octokit
protected ApiException(ApiException innerException)
{
Ensure.ArgumentNotNull(innerException, "innerException");
+
StatusCode = innerException.StatusCode;
ApiError = innerException.ApiError;
}
+ protected ApiException(HttpStatusCode statusCode, Exception innerException)
+ : base(null, innerException)
+ {
+ ApiError = new ApiError();
+ StatusCode = statusCode;
+ }
+
+ protected ApiException(ApiError apiError, HttpStatusCode statusCode, Exception innerException)
+ : base(null, innerException)
+ {
+ Ensure.ArgumentNotNull(apiError, "apiError");
+
+ ApiError = apiError;
+ StatusCode = statusCode;
+ }
+
public override string Message
{
get { return ApiErrorMessageSafe ?? "An error occurred with this API request"; }
diff --git a/Octokit/Exceptions/ApiValidationException.cs b/Octokit/Exceptions/ApiValidationException.cs
index 27f06a09..2e4c2650 100644
--- a/Octokit/Exceptions/ApiValidationException.cs
+++ b/Octokit/Exceptions/ApiValidationException.cs
@@ -3,7 +3,6 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Runtime.Serialization;
-using Octokit.Internal;
namespace Octokit
{
@@ -20,7 +19,7 @@ namespace Octokit
///
/// Constructs an instance of ApiValidationException
///
- public ApiValidationException() : base(new Response { StatusCode = (HttpStatusCode)422})
+ public ApiValidationException() : base((HttpStatusCode)422, null)
{
}
diff --git a/Octokit/Exceptions/AuthorizationException.cs b/Octokit/Exceptions/AuthorizationException.cs
index a73eeb24..ba8806b3 100644
--- a/Octokit/Exceptions/AuthorizationException.cs
+++ b/Octokit/Exceptions/AuthorizationException.cs
@@ -3,7 +3,6 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Runtime.Serialization;
-using Octokit.Internal;
namespace Octokit
{
@@ -20,7 +19,7 @@ namespace Octokit
///
/// Constructs an instance of AuthorizationException
///
- public AuthorizationException() : base(new Response { StatusCode = HttpStatusCode.Unauthorized })
+ public AuthorizationException() : base(HttpStatusCode.Unauthorized, null)
{
}
@@ -45,6 +44,11 @@ namespace Octokit
"AuthorizationException created with wrong status code");
}
+ public AuthorizationException(HttpStatusCode httpStatusCode, Exception innerException)
+ : base(httpStatusCode, innerException)
+ {
+ }
+
#if !NETFX_CORE
///
/// Constructs an instance of AuthorizationException.
diff --git a/Octokit/Exceptions/TwoFactorChallengeFailedException.cs b/Octokit/Exceptions/TwoFactorChallengeFailedException.cs
index 0f367bdf..7a93bbae 100644
--- a/Octokit/Exceptions/TwoFactorChallengeFailedException.cs
+++ b/Octokit/Exceptions/TwoFactorChallengeFailedException.cs
@@ -2,7 +2,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Runtime.Serialization;
-using Octokit.Internal;
namespace Octokit
{
@@ -20,7 +19,7 @@ namespace Octokit
/// Constructs an instance of TwoFactorChallengeFailedException
///
public TwoFactorChallengeFailedException() :
- base(new Response { StatusCode = HttpStatusCode.Unauthorized })
+ base(HttpStatusCode.Unauthorized, null)
{
}
@@ -29,7 +28,7 @@ namespace Octokit
///
/// The inner exception
public TwoFactorChallengeFailedException(Exception innerException)
- : base(new Response { StatusCode = HttpStatusCode.Unauthorized }, innerException)
+ : base(HttpStatusCode.Unauthorized, innerException)
{
}
diff --git a/Octokit/Exceptions/TwoFactorRequiredException.cs b/Octokit/Exceptions/TwoFactorRequiredException.cs
index 390a7ef4..ad7a2ee3 100644
--- a/Octokit/Exceptions/TwoFactorRequiredException.cs
+++ b/Octokit/Exceptions/TwoFactorRequiredException.cs
@@ -3,7 +3,6 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Runtime.Serialization;
-using Octokit.Internal;
namespace Octokit
{
@@ -29,8 +28,9 @@ namespace Octokit
///
/// Expected 2FA response type
public TwoFactorRequiredException(TwoFactorType twoFactorType)
- : this(new Response { StatusCode = HttpStatusCode.Unauthorized}, twoFactorType)
+ : base(HttpStatusCode.Unauthorized, null)
{
+ TwoFactorType = twoFactorType;
}
///