Skip to content

Commit d7a6233

Browse files
committed
Deserialize auth error for 401 response.
1 parent c4a89b1 commit d7a6233

21 files changed

+2840
-35
lines changed

Dropbox.Api/Auth/AuthError.cs

Lines changed: 418 additions & 0 deletions
Large diffs are not rendered by default.

Dropbox.Api/Dropbox.Api.Doc.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@
7777
<Compile Include="Async\PollEmptyResult.cs" />
7878
<Compile Include="Async\PollError.cs" />
7979
<Compile Include="Async\PollResultBase.cs" />
80+
<Compile Include="Auth\AuthError.cs" />
8081
<Compile Include="DropboxClient.cs" />
82+
<Compile Include="DropboxRequestHandlerFactory.cs" />
8183
<Compile Include="DropboxTeamClient.cs" />
8284
<Compile Include="Files\CommitInfo.cs" />
8385
<Compile Include="Files\CreateFolderArg.cs" />
@@ -154,7 +156,9 @@
154156
<Compile Include="Sharing\CreateSharedLinkWithSettingsArg.cs" />
155157
<Compile Include="Sharing\CreateSharedLinkWithSettingsError.cs" />
156158
<Compile Include="Sharing\FileLinkMetadata.cs" />
159+
<Compile Include="Sharing\FolderAction.cs" />
157160
<Compile Include="Sharing\FolderLinkMetadata.cs" />
161+
<Compile Include="Sharing\FolderPermission.cs" />
158162
<Compile Include="Sharing\FolderPolicy.cs" />
159163
<Compile Include="Sharing\GetMetadataArgs.cs" />
160164
<Compile Include="Sharing\GetSharedLinkFileError.cs" />
@@ -179,6 +183,8 @@
179183
<Compile Include="Sharing\ListSharedLinksArg.cs" />
180184
<Compile Include="Sharing\ListSharedLinksError.cs" />
181185
<Compile Include="Sharing\ListSharedLinksResult.cs" />
186+
<Compile Include="Sharing\MemberAction.cs" />
187+
<Compile Include="Sharing\MemberPermission.cs" />
182188
<Compile Include="Sharing\MemberPolicy.cs" />
183189
<Compile Include="Sharing\MemberSelector.cs" />
184190
<Compile Include="Sharing\MembershipInfo.cs" />
@@ -188,6 +194,7 @@
188194
<Compile Include="Sharing\MountFolderError.cs" />
189195
<Compile Include="Sharing\PathLinkMetadata.cs" />
190196
<Compile Include="Sharing\PendingUploadMode.cs" />
197+
<Compile Include="Sharing\PermissionDeniedReason.cs" />
191198
<Compile Include="Sharing\RelinquishFolderMembershipArg.cs" />
192199
<Compile Include="Sharing\RelinquishFolderMembershipError.cs" />
193200
<Compile Include="Sharing\RemoveFolderMemberArg.cs" />

Dropbox.Api/Dropbox.Api.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@
9797
<Compile Include="Async\PollEmptyResult.cs" />
9898
<Compile Include="Async\PollError.cs" />
9999
<Compile Include="Async\PollResultBase.cs" />
100+
<Compile Include="Auth\AuthError.cs" />
100101
<Compile Include="DropboxClient.cs" />
102+
<Compile Include="DropboxRequestHandlerFactory.cs" />
101103
<Compile Include="DropboxTeamClient.cs" />
102104
<Compile Include="Files\CommitInfo.cs" />
103105
<Compile Include="Files\CreateFolderArg.cs" />
@@ -174,7 +176,9 @@
174176
<Compile Include="Sharing\CreateSharedLinkWithSettingsArg.cs" />
175177
<Compile Include="Sharing\CreateSharedLinkWithSettingsError.cs" />
176178
<Compile Include="Sharing\FileLinkMetadata.cs" />
179+
<Compile Include="Sharing\FolderAction.cs" />
177180
<Compile Include="Sharing\FolderLinkMetadata.cs" />
181+
<Compile Include="Sharing\FolderPermission.cs" />
178182
<Compile Include="Sharing\FolderPolicy.cs" />
179183
<Compile Include="Sharing\GetMetadataArgs.cs" />
180184
<Compile Include="Sharing\GetSharedLinkFileError.cs" />
@@ -199,6 +203,8 @@
199203
<Compile Include="Sharing\ListSharedLinksArg.cs" />
200204
<Compile Include="Sharing\ListSharedLinksError.cs" />
201205
<Compile Include="Sharing\ListSharedLinksResult.cs" />
206+
<Compile Include="Sharing\MemberAction.cs" />
207+
<Compile Include="Sharing\MemberPermission.cs" />
202208
<Compile Include="Sharing\MemberPolicy.cs" />
203209
<Compile Include="Sharing\MemberSelector.cs" />
204210
<Compile Include="Sharing\MembershipInfo.cs" />
@@ -208,6 +214,7 @@
208214
<Compile Include="Sharing\MountFolderError.cs" />
209215
<Compile Include="Sharing\PathLinkMetadata.cs" />
210216
<Compile Include="Sharing\PendingUploadMode.cs" />
217+
<Compile Include="Sharing\PermissionDeniedReason.cs" />
211218
<Compile Include="Sharing\RelinquishFolderMembershipArg.cs" />
212219
<Compile Include="Sharing\RelinquishFolderMembershipError.cs" />
213220
<Compile Include="Sharing\RemoveFolderMemberArg.cs" />

Dropbox.Api/Dropbox.Api.nuspec

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>$id$</id>
5-
<version>2.3.1</version>
5+
<version>2.3.2</version>
66
<title>Dropbox v2 API Beta</title>
77
<authors>Dropbox Inc</authors>
88
<owners>Dropbox Inc</owners>
@@ -12,7 +12,13 @@
1212
<iconUrl>https://cf.dropboxstatic.com/static/images/icons/blue_dropbox_glyph.png</iconUrl>
1313
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1414
<description>Portable class library for accessing the Dropbox v2 API</description>
15-
<releaseNotes>Preview Release. Include Dropbox Business endpoints. Bug fixes.</releaseNotes>
15+
<releaseNotes>Preview Release.
16+
17+
What's new:
18+
-Include Dropbox Business endpoints.
19+
20+
Bug fixes:
21+
-Now throw ApiException&lt;AuthError&gt; instead of AuthException</releaseNotes>
1622
<copyright>Copyright (c) Dropbox Inc. 2015</copyright>
1723
<tags>Dropbox Api</tags>
1824
</metadata>

Dropbox.Api/DropboxClient.common.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public DropboxClient(
3232
int maxRetriesOnError = 4,
3333
string userAgent = null,
3434
HttpClient httpClient = null)
35-
: this(new DrpoboxRequestHandlerOptions(oauth2AccessToken, maxRetriesOnError, userAgent, httpClient: httpClient))
35+
: this(new DropboxRequestHandlerOptions(oauth2AccessToken, maxRetriesOnError, userAgent, httpClient: httpClient))
3636
{
3737
if (oauth2AccessToken == null)
3838
{
@@ -46,9 +46,9 @@ public DropboxClient(
4646
/// <param name="options">The request handler options.</param>
4747
/// <param name="selectUser">The member id of the selected user. If provided together with
4848
/// a team access token, actions will be performed on this this user's Dropbox.</param>
49-
internal DropboxClient(DrpoboxRequestHandlerOptions options, string selectUser = null)
49+
internal DropboxClient(DropboxRequestHandlerOptions options, string selectUser = null)
5050
{
51-
this.InitializeRoutes(new DropboxRequestHandler(options, selectUser));
51+
this.InitializeRoutes(DropboxRequestHandlerFactory.Create(options, selectUser));
5252
}
5353

5454
/// <summary>
@@ -67,7 +67,7 @@ public sealed partial class DropboxTeamClient
6767
/// <summary>
6868
/// The request handler options.
6969
/// </summary>
70-
private readonly DrpoboxRequestHandlerOptions options;
70+
private readonly DropboxRequestHandlerOptions options;
7171

7272
/// <summary>
7373
/// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxTeamClient"/> class.
@@ -93,8 +93,8 @@ public DropboxTeamClient(
9393
throw new ArgumentNullException("oauth2AccessToken");
9494
}
9595

96-
this.options = new DrpoboxRequestHandlerOptions(oauth2AccessToken, maxRetriesOnError, userAgent, httpClient: httpClient);
97-
this.InitializeRoutes(new DropboxRequestHandler(this.options));
96+
this.options = new DropboxRequestHandlerOptions(oauth2AccessToken, maxRetriesOnError, userAgent, httpClient: httpClient);
97+
this.InitializeRoutes(DropboxRequestHandlerFactory.Create(this.options));
9898
}
9999

100100
/// <summary>
@@ -163,6 +163,7 @@ public BadInputException(string message, Uri uri = null)
163163
/// <summary>
164164
/// An HTTP exception that is caused by the server reporting an authentication problem.
165165
/// </summary>
166+
[Obsolete("This exception is no longer thrown. Please catch ApiException<AuthError> instead.")]
166167
public class AuthException : HttpException
167168
{
168169
/// <summary>

Dropbox.Api/DropboxRequestHandler.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ namespace Dropbox.Api
2424
/// <summary>
2525
/// The object used to to make requests to the Dropbox API.
2626
/// </summary>
27-
internal sealed class DropboxRequestHandler : ITransport
27+
/// <typeparam name="TAuthError">The type for auth error.</typeparam>
28+
internal sealed class DropboxRequestHandler<TAuthError> : ITransport
2829
{
2930
/// <summary>
3031
/// The API version
@@ -49,23 +50,36 @@ internal sealed class DropboxRequestHandler : ITransport
4950
/// <summary>
5051
/// The configuration options for dropbox client.
5152
/// </summary>
52-
private readonly DrpoboxRequestHandlerOptions options;
53+
private readonly DropboxRequestHandlerOptions options;
54+
55+
/// <summary>
56+
/// The auth error decoder.
57+
/// </summary>
58+
private readonly IDecoder<TAuthError> authErrorDecoder;
5359

5460
/// <summary>
5561
/// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxRequestHandler"/> class.
5662
/// </summary>
5763
/// <param name="options">The configuration options for dropbox client.</param>
64+
/// <param name="authErrorDecoder">The auth error decoder.</param>
5865
/// <param name="selectUser">The member id of the selected user.</param>
5966
public DropboxRequestHandler(
60-
DrpoboxRequestHandlerOptions options,
67+
DropboxRequestHandlerOptions options,
68+
IDecoder<TAuthError> authErrorDecoder,
6169
string selectUser = null)
6270
{
6371
if (options == null)
6472
{
6573
throw new ArgumentNullException("options");
6674
}
6775

76+
if (authErrorDecoder == null)
77+
{
78+
throw new ArgumentNullException("authErrorDecoder");
79+
}
80+
6881
this.options = options;
82+
this.authErrorDecoder = authErrorDecoder;
6983
this.selectUser = selectUser;
7084
}
7185

@@ -399,9 +413,8 @@ private async Task<Result> RequestJsonString(
399413
}
400414
else if (response.StatusCode == HttpStatusCode.Unauthorized)
401415
{
402-
var text = await response.Content.ReadAsStringAsync();
403-
text = this.CheckForError(text);
404-
throw new AuthException(text, uri);
416+
var reason = await response.Content.ReadAsStringAsync();
417+
throw ApiException<TAuthError>.Decode(reason, this.authErrorDecoder);
405418
}
406419
else if ((int)response.StatusCode == 429)
407420
{
@@ -593,7 +606,7 @@ internal class HostType
593606
/// <summary>
594607
/// The class which contains configurations for the request handler.
595608
/// </summary>
596-
internal sealed class DrpoboxRequestHandlerOptions
609+
internal sealed class DropboxRequestHandlerOptions
597610
{
598611
/// <summary>
599612
/// The default api domain
@@ -634,7 +647,7 @@ internal sealed class DrpoboxRequestHandlerOptions
634647
/// this is for internal Dropbox use only.</param>
635648
/// <param name="httpClient">The custom http client. If not provided, a default
636649
/// http client will be created.</param>
637-
public DrpoboxRequestHandlerOptions(
650+
public DropboxRequestHandlerOptions(
638651
string oauth2AccessToken = null,
639652
int maxRetriesOnError = 4,
640653
string userAgent = null,
@@ -643,7 +656,7 @@ public DrpoboxRequestHandlerOptions(
643656
string apiNotifyHostname = DefaultApiNotifyDomain,
644657
HttpClient httpClient = null)
645658
{
646-
var name = new AssemblyName(typeof(DrpoboxRequestHandlerOptions).Assembly.FullName);
659+
var name = new AssemblyName(typeof(DropboxRequestHandlerOptions).Assembly.FullName);
647660
var sdkVersion = name.Version.ToString();
648661

649662
this.UserAgent = userAgent == null
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// <auto-generated>
2+
// Auto-generated by BabelAPI, do not modify.
3+
// </auto-generated>
4+
5+
namespace Dropbox.Api
6+
{
7+
using sys = System;
8+
9+
using Dropbox.Api.Babel;
10+
using Dropbox.Api.Auth;
11+
12+
internal static class DropboxRequestHandlerFactory
13+
{
14+
15+
/// <summary>
16+
/// <para>Creates a <see cref="DropboxRequestHandler{T}"/> instance.</para>
17+
/// </summary>
18+
/// <param name="options">The request handler options.</param>
19+
/// <param name="selectUser">The select user id.</param>
20+
public static ITransport Create(DropboxRequestHandlerOptions options, string selectUser = null)
21+
{
22+
return new DropboxRequestHandler<AuthError>(options, AuthError.Decoder, selectUser);
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)