mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-22 15:15:19 +00:00
Stop manufacturing Response objects just to create an exception
This commit is contained in:
@@ -32,7 +32,7 @@ namespace Octokit
|
|||||||
/// <param name="message">The error message</param>
|
/// <param name="message">The error message</param>
|
||||||
/// <param name="httpStatusCode">The HTTP status code from the response</param>
|
/// <param name="httpStatusCode">The HTTP status code from the response</param>
|
||||||
public ApiException(string message, HttpStatusCode httpStatusCode)
|
public ApiException(string message, HttpStatusCode httpStatusCode)
|
||||||
: this(new Response {Body = message, StatusCode = httpStatusCode})
|
: this(GetApiErrorFromExceptionMessage(message), httpStatusCode, null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ namespace Octokit
|
|||||||
/// <param name="message">The error message</param>
|
/// <param name="message">The error message</param>
|
||||||
/// <param name="innerException">The inner exception</param>
|
/// <param name="innerException">The inner exception</param>
|
||||||
public ApiException(string message, Exception innerException)
|
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)
|
protected ApiException(ApiException innerException)
|
||||||
{
|
{
|
||||||
Ensure.ArgumentNotNull(innerException, "innerException");
|
Ensure.ArgumentNotNull(innerException, "innerException");
|
||||||
|
|
||||||
StatusCode = innerException.StatusCode;
|
StatusCode = innerException.StatusCode;
|
||||||
ApiError = innerException.ApiError;
|
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
|
public override string Message
|
||||||
{
|
{
|
||||||
get { return ApiErrorMessageSafe ?? "An error occurred with this API request"; }
|
get { return ApiErrorMessageSafe ?? "An error occurred with this API request"; }
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using System.Diagnostics;
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Octokit.Internal;
|
|
||||||
|
|
||||||
namespace Octokit
|
namespace Octokit
|
||||||
{
|
{
|
||||||
@@ -20,7 +19,7 @@ namespace Octokit
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs an instance of ApiValidationException
|
/// Constructs an instance of ApiValidationException
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ApiValidationException() : base(new Response { StatusCode = (HttpStatusCode)422})
|
public ApiValidationException() : base((HttpStatusCode)422, null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using System.Diagnostics;
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Octokit.Internal;
|
|
||||||
|
|
||||||
namespace Octokit
|
namespace Octokit
|
||||||
{
|
{
|
||||||
@@ -20,7 +19,7 @@ namespace Octokit
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs an instance of AuthorizationException
|
/// Constructs an instance of AuthorizationException
|
||||||
/// </summary>
|
/// </summary>
|
||||||
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");
|
"AuthorizationException created with wrong status code");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AuthorizationException(HttpStatusCode httpStatusCode, Exception innerException)
|
||||||
|
: base(httpStatusCode, innerException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
#if !NETFX_CORE
|
#if !NETFX_CORE
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs an instance of AuthorizationException.
|
/// Constructs an instance of AuthorizationException.
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Octokit.Internal;
|
|
||||||
|
|
||||||
namespace Octokit
|
namespace Octokit
|
||||||
{
|
{
|
||||||
@@ -20,7 +19,7 @@ namespace Octokit
|
|||||||
/// Constructs an instance of TwoFactorChallengeFailedException
|
/// Constructs an instance of TwoFactorChallengeFailedException
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TwoFactorChallengeFailedException() :
|
public TwoFactorChallengeFailedException() :
|
||||||
base(new Response { StatusCode = HttpStatusCode.Unauthorized })
|
base(HttpStatusCode.Unauthorized, null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +28,7 @@ namespace Octokit
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="innerException">The inner exception</param>
|
/// <param name="innerException">The inner exception</param>
|
||||||
public TwoFactorChallengeFailedException(Exception innerException)
|
public TwoFactorChallengeFailedException(Exception innerException)
|
||||||
: base(new Response { StatusCode = HttpStatusCode.Unauthorized }, innerException)
|
: base(HttpStatusCode.Unauthorized, innerException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using System.Diagnostics;
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Octokit.Internal;
|
|
||||||
|
|
||||||
namespace Octokit
|
namespace Octokit
|
||||||
{
|
{
|
||||||
@@ -29,8 +28,9 @@ namespace Octokit
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="twoFactorType">Expected 2FA response type</param>
|
/// <param name="twoFactorType">Expected 2FA response type</param>
|
||||||
public TwoFactorRequiredException(TwoFactorType twoFactorType)
|
public TwoFactorRequiredException(TwoFactorType twoFactorType)
|
||||||
: this(new Response { StatusCode = HttpStatusCode.Unauthorized}, twoFactorType)
|
: base(HttpStatusCode.Unauthorized, null)
|
||||||
{
|
{
|
||||||
|
TwoFactorType = twoFactorType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user