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; } + } }