@@ -8,14 +8,13 @@ namespace Dropbox.Api
88{
99 using System ;
1010
11- using Dropbox . Api . Babel ;
12-
1311 /// <summary>
1412 /// The exception type that will be raised by an <see cref="ITransport" />
15- /// implementation if there is an error processing the request.
13+ /// implementation if there is an error processing the request which is caused by
14+ /// failure in API route.
1615 /// </summary>
1716 /// <typeparam name="TError">The type of the error.</typeparam>
18- public sealed class ApiException < TError > : Exception
17+ public sealed class ApiException < TError > : StructuredException < TError >
1918 {
2019 /// <summary>
2120 /// Initializes a new instance of the <see cref="ApiException{TError}"/> class.
@@ -52,93 +51,8 @@ public ApiException(TError errorResponse, string message)
5251 /// <param name="message">The message.</param>
5352 /// <param name="inner">The inner.</param>
5453 public ApiException ( TError errorResponse , string message , Exception inner )
55- : base ( message , inner )
54+ : base ( errorResponse , message , inner )
5655 {
57- this . ErrorResponse = errorResponse ;
58- this . ErrorMessage = message ;
59- }
60-
61- /// <summary>
62- /// Gets the error response.
63- /// </summary>
64- /// <value>
65- /// The error response.
66- /// </value>
67- public TError ErrorResponse { get ; private set ; }
68-
69- /// <summary>
70- /// Gets the exception message.
71- /// </summary>
72- public override string Message
73- {
74- get { return this . ErrorMessage ; }
75- }
76-
77- /// <summary>
78- /// Gets or sets the error message.
79- /// </summary>
80- private string ErrorMessage { get ; set ; }
81-
82- /// <summary>
83- /// Decode from given json using given decoder.
84- /// </summary>
85- /// <param name="json">The json.</param>
86- /// <param name="errorDecoder">The error json.</param>
87- /// <returns>The <see cref="ApiException{TError}"/></returns>
88- internal static ApiException < TError > Decode ( string json , IDecoder < TError > errorDecoder )
89- {
90- return JsonReader . Read ( json , new ApiExceptionDecoder ( errorDecoder ) ) ;
91- }
92-
93- /// <summary>
94- /// The exception decoder.
95- /// </summary>
96- private class ApiExceptionDecoder : StructDecoder < ApiException < TError > >
97- {
98- /// <summary>
99- /// The error decoder.
100- /// </summary>
101- private readonly IDecoder < TError > errorDecoder ;
102-
103- /// <summary>
104- /// Initializes a new instance of the <see cref="ApiExceptionDecoder"/> class.
105- /// </summary>
106- /// <param name="errorDecoder">The error decoder.</param>
107- public ApiExceptionDecoder ( IDecoder < TError > errorDecoder )
108- {
109- this . errorDecoder = errorDecoder ;
110- }
111-
112- /// <summary>
113- /// Create a struct instance.
114- /// </summary>
115- /// <returns>The struct instance.</returns>
116- protected override ApiException < TError > Create ( )
117- {
118- return new ApiException < TError > ( ) ;
119- }
120-
121- /// <summary>
122- /// Set given field.
123- /// </summary>
124- /// <param name="value">The field value.</param>
125- /// <param name="fieldName">The field name.</param>
126- /// <param name="reader">The reader.</param>
127- protected override void SetField ( ApiException < TError > value , string fieldName , IJsonReader reader )
128- {
129- switch ( fieldName )
130- {
131- case "error" :
132- value . ErrorResponse = this . errorDecoder . Decode ( reader ) ;
133- break ;
134- case "error_summary" :
135- value . ErrorMessage = StringDecoder . Instance . Decode ( reader ) ;
136- break ;
137- default :
138- reader . Skip ( ) ;
139- break ;
140- }
141- }
14256 }
14357 }
14458}
0 commit comments