@@ -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
0 commit comments