using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
namespace Octokit
{
#if !NETFX_CORE
///
/// Represents a failed 2FA challenge from the API
///
[Serializable]
#endif
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors",
Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")]
public class TwoFactorChallengeFailedException : TwoFactorAuthorizationException
{
///
/// Constructs an instance of TwoFactorChallengeFailedException
///
public TwoFactorChallengeFailedException() : base(TwoFactorType.None, null)
{
}
///
/// Constructs an instance of TwoFactorChallengeFailedException
///
/// The authorization code that was incorrect
/// The inner exception
public TwoFactorChallengeFailedException(
string authorizationCode,
ApiException innerException)
: base(ParseTwoFactorType(innerException), innerException)
{
AuthorizationCode = authorizationCode;
}
public override string Message
{
get { return "The two-factor authentication code supplied is not correct"; }
}
public string AuthorizationCode { get; private set; }
static TwoFactorType ParseTwoFactorType(ApiException exception)
{
return exception == null ? TwoFactorType.None : Connection.ParseTwoFactorType(exception.HttpResponse);
}
#if !NETFX_CORE
///
/// Constructs an instance of TwoFactorChallengeFailedException.
///
///
/// The that holds the
/// serialized object data about the exception being thrown.
///
///
/// The that contains
/// contextual information about the source or destination.
///
protected TwoFactorChallengeFailedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
if (info == null) return;
AuthorizationCode = info.GetString("AuthorizationCode");
}
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("AuthorizationCode", AuthorizationCode);
}
#endif
}
}