From ffbf4cc3532dfe691ecfa8c75cfa6bc75f1b8dca Mon Sep 17 00:00:00 2001 From: Qiming Yuan Date: Tue, 12 Jan 2016 15:33:16 -0800 Subject: [PATCH] Bug fixes. --- Dropbox.Api/Dropbox.Api.nuspec | 4 ++-- Dropbox.Api/DropboxOauth2Helper.cs | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Dropbox.Api/Dropbox.Api.nuspec b/Dropbox.Api/Dropbox.Api.nuspec index ebd09de3ca..e509dece81 100644 --- a/Dropbox.Api/Dropbox.Api.nuspec +++ b/Dropbox.Api/Dropbox.Api.nuspec @@ -2,7 +2,7 @@ $id$ - 2.1.1 + 2.2.1 Dropbox v2 API Beta Dropbox Inc Dropbox Inc @@ -12,7 +12,7 @@ https://cf.dropboxstatic.com/static/images/icons/blue_dropbox_glyph.png false Portable class library for accessing the Dropbox v2 API - Preview Release. Minor bug fixes. + Preview Release. Bug fixes. Copyright (c) Dropbox Inc. 2015 Dropbox Api diff --git a/Dropbox.Api/DropboxOauth2Helper.cs b/Dropbox.Api/DropboxOauth2Helper.cs index f2bc13d79f..1d613addb4 100644 --- a/Dropbox.Api/DropboxOauth2Helper.cs +++ b/Dropbox.Api/DropboxOauth2Helper.cs @@ -8,6 +8,7 @@ namespace Dropbox.Api { using System; using System.Collections.Generic; + using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; @@ -378,6 +379,11 @@ public static async Task ProcessCodeFlowAsync(string code, strin var raw = await response.Content.ReadAsStringAsync(); var json = JObject.Parse(raw); + if (response.StatusCode != HttpStatusCode.OK) + { + throw new OAuth2Exception(json["error"].ToString(), json.Value("error_description")); + } + return new OAuth2Response( json["access_token"].ToString(), json["uid"].ToString(), @@ -528,4 +534,25 @@ internal OAuth2Response(string accessToken, string uid, string state, string tok /// public string TokenType { get; private set; } } + + /// + /// Exception when error occurs during oauth2 flow. + /// + public sealed class OAuth2Exception : Exception + { + /// + /// Initializes a new instance of the class. + /// + /// The message. + /// The error description + public OAuth2Exception(string message, string errorDescription = null) : base(message) + { + this.ErrorDescription = errorDescription; + } + + /// + /// Gets the error description. + /// + public string ErrorDescription { get; private set; } + } }