Skip to content

Commit

Permalink
Merge pull request #208 from digitallez/master
Browse files Browse the repository at this point in the history
Добавлена обработка ошибки NeedValidation
  • Loading branch information
inyutin-maxim committed Mar 6, 2016
2 parents 69fd6b5 + f12186a commit d5db1e5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
49 changes: 49 additions & 0 deletions VkNet/Exception/NeedValidationException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace VkNet.Exception
{
using System;
using System.Runtime.Serialization;

using Enums.Filters;

/// <summary>
/// Исключение, которое выбрасывается в случаях,
/// когда требуется дополнительная проверка пользователя,
/// например при авторизации из подозрительного места
///
/// В этом случае необходимо открыть браузер со страницей, указанной в поле redirect_uri и ждать,
/// пока пользователь будет направлен на страницу blank.html с параметром success=1 в случае успеха и fail=1
/// в случае, если пользователь отменил проверку своего аккаунта.
/// Для тестового вызова проверки добавьте параметр test_redirect_uri=1.
///
/// </summary>
[Serializable]
public class NeedValidationException : VkApiException
{
/// <summary>
/// Адрес который необходимо открыть в браузере.
/// </summary>
public Uri redirectUri { get; private set; }


/// <summary>
/// Инициализирует новый экземпляр класса <see cref="VkApiAuthorizationException"/>.
/// </summary>
/// <param name="message">Описание исключения.</param>
/// <param name="strRedirectUri">Адрес который необходимо открыть в браузере.</param>
public NeedValidationException(string message, string strRedirectUri) : base(message)
{
redirectUri = new Uri(strRedirectUri);
}


/// <summary>
/// Инициализирует новый экземпляр класса <see cref="AccessTokenInvalidException"/> на основе ранее сериализованных данных.
/// </summary>
/// <param name="info">Содержит все данные, необходимые для десериализации.</param>
/// <param name="context">Описывает источник и назначение данного сериализованного потока и предоставляет дополнительный,
/// определяемый вызывающим, контекст.</param>
protected NeedValidationException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
5 changes: 5 additions & 0 deletions VkNet/Utils/VkErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public static void IfErrorThrowException(string json)
var img = Convert.ToString(response["captcha_img"]);
throw new CaptchaNeededException(sid, img);
}
case 17:
{
var redirectUri = Convert.ToString(response["redirect_uri"]);
throw new NeedValidationException(message, redirectUri);
}
case 5:
{
throw new UserAuthorizationFailException(message, code);
Expand Down
1 change: 1 addition & 0 deletions VkNet/VkNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<Compile Include="Enums\SafetyEnums\FeedType.cs" />
<Compile Include="Enums\SafetyEnums\VideoCatalogItemType.cs" />
<Compile Include="Enums\SafetyEnums\VideoCatalogType.cs" />
<Compile Include="Exception\NeedValidationException.cs" />
<Compile Include="Exception\OutOfLimitsException.cs" />
<Compile Include="Model\AccountChangePasswordResult.cs" />
<Compile Include="Model\DocumentType.cs" />
Expand Down

0 comments on commit d5db1e5

Please sign in to comment.