Implement 403 exception handling

This implements exception handling for the various 403 cases based off
of the Octokit.rb implementation.
https://github.com/octokit/octokit.rb/blob/master/lib/octokit/error.rb

Fixes #85
This commit is contained in:
Haacked
2013-10-17 21:39:26 -07:00
parent 8406b42e44
commit a1887837be
23 changed files with 639 additions and 186 deletions
@@ -1,29 +1,33 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Runtime.Serialization;
using Octokit.Internal;
namespace Octokit
{
#if !NETFX_CORE
[Serializable]
#endif
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors",
Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")]
public class TwoFactorRequiredException : AuthorizationException
{
public TwoFactorRequiredException()
public TwoFactorRequiredException() : this(TwoFactorType.None)
{
}
public TwoFactorRequiredException(string message) : base(message)
public TwoFactorRequiredException(TwoFactorType twoFactorType)
: this(new ApiResponse<object> { StatusCode = HttpStatusCode.Unauthorized}, twoFactorType)
{
}
public TwoFactorRequiredException(string message, Exception innerException) : base(message, innerException)
public TwoFactorRequiredException(IResponse response, TwoFactorType twoFactorType) : base(response)
{
}
Debug.Assert(response != null && response.StatusCode == HttpStatusCode.Unauthorized,
"TwoFactorRequiredException status code should be 401");
public TwoFactorRequiredException(string message, TwoFactorType twoFactorType)
: base(message)
{
TwoFactorType = twoFactorType;
}