Files
octokit.net/Octokit/Exceptions/TwoFactorRequiredException.cs
Mickaël Derriey 13d5dab516 Port to .NET Core (#1503)
Port to .NET Core
2017-01-21 14:42:02 +10:00

72 lines
2.4 KiB
C#

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Net;
#if !NO_SERIALIZABLE
using System.Runtime.Serialization;
#endif
namespace Octokit
{
/// <summary>
///
/// </summary>
#if !NO_SERIALIZABLE
[Serializable]
#endif
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors",
Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")]
public class TwoFactorRequiredException : TwoFactorAuthorizationException
{
/// <summary>
/// Constructs an instance of TwoFactorRequiredException.
/// </summary>
public TwoFactorRequiredException() : this(TwoFactorType.None)
{
}
/// <summary>
/// Constructs an instance of TwoFactorRequiredException.
/// </summary>
/// <param name="twoFactorType">Expected 2FA response type</param>
public TwoFactorRequiredException(TwoFactorType twoFactorType) : base(twoFactorType, null)
{
}
/// <summary>
/// Constructs an instance of TwoFactorRequiredException.
/// </summary>
/// <param name="response">The HTTP payload from the server</param>
/// <param name="twoFactorType">Expected 2FA response type</param>
public TwoFactorRequiredException(IResponse response, TwoFactorType twoFactorType)
: base(response, twoFactorType)
{
Debug.Assert(response != null && response.StatusCode == HttpStatusCode.Unauthorized,
"TwoFactorRequiredException status code should be 401");
}
public override string Message
{
get { return ApiErrorMessageSafe ?? "Two-factor authentication code is required"; }
}
#if !NO_SERIALIZABLE
/// <summary>
/// Constructs an instance of TwoFactorRequiredException.
/// </summary>
/// <param name="info">
/// The <see cref="SerializationInfo"/> that holds the
/// serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="StreamingContext"/> that contains
/// contextual information about the source or destination.
/// </param>
protected TwoFactorRequiredException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endif
}
}