@@ -43,37 +43,33 @@ public interface IAccountBalances
4343 public class AccountBalances : IAccountBalances
4444 {
4545 public SDKConfig SDKConfiguration { get ; private set ; }
46- private const string _language = "csharp" ;
47- private const string _sdkVersion = "9.0.2" ;
48- private const string _sdkGenVersion = "2.486.1" ;
49- private const string _openapiDocVersion = "3.0.0" ;
50- private const string _userAgent = "speakeasy-sdk/csharp 9.0.2 2.486.1 3.0.0 Codat.Lending" ;
51- private string _serverUrl = "" ;
52- private ISpeakeasyHttpClient _client ;
53- private Func < Codat . Lending . Models . Components . Security > ? _securitySource ;
54-
55- public AccountBalances ( ISpeakeasyHttpClient client , Func < Codat . Lending . Models . Components . Security > ? securitySource , string serverUrl , SDKConfig config )
46+
47+ private const string _language = Constants . Language ;
48+ private const string _sdkVersion = Constants . SdkVersion ;
49+ private const string _sdkGenVersion = Constants . SdkGenVersion ;
50+ private const string _openapiDocVersion = Constants . OpenApiDocVersion ;
51+
52+ public AccountBalances ( SDKConfig config )
5653 {
57- _client = client ;
58- _securitySource = securitySource ;
59- _serverUrl = serverUrl ;
6054 SDKConfiguration = config ;
6155 }
6256
6357 public async Task < ListBankingAccountBalancesResponse > ListAsync ( ListBankingAccountBalancesRequest request , RetryConfig ? retryConfig = null )
6458 {
59+ if ( request == null ) throw new ArgumentNullException ( nameof ( request ) ) ;
60+
6561 string baseUrl = this . SDKConfiguration . GetTemplatedServerUrl ( ) ;
66- var urlString = URLBuilder . Build ( baseUrl , "/companies/{companyId}/connections/{connectionId}/data/banking-accountBalances" , request ) ;
62+ var urlString = URLBuilder . Build ( baseUrl , "/companies/{companyId}/connections/{connectionId}/data/banking-accountBalances" , request , null ) ;
6763
6864 var httpRequest = new HttpRequestMessage ( HttpMethod . Get , urlString ) ;
69- httpRequest . Headers . Add ( "user-agent" , _userAgent ) ;
65+ httpRequest . Headers . Add ( "user-agent" , SDKConfiguration . UserAgent ) ;
7066
71- if ( _securitySource != null )
67+ if ( SDKConfiguration . SecuritySource != null )
7268 {
73- httpRequest = new SecurityMetadata ( _securitySource ) . Apply ( httpRequest ) ;
69+ httpRequest = new SecurityMetadata ( SDKConfiguration . SecuritySource ) . Apply ( httpRequest ) ;
7470 }
7571
76- var hookCtx = new HookContext ( "list-banking-account-balances" , null , _securitySource ) ;
72+ var hookCtx = new HookContext ( SDKConfiguration , baseUrl , "list-banking-account-balances" , null , SDKConfiguration . SecuritySource ) ;
7773
7874 httpRequest = await this . SDKConfiguration . Hooks . BeforeRequestAsync ( new BeforeRequestContext ( hookCtx ) , httpRequest ) ;
7975 if ( retryConfig == null )
@@ -107,8 +103,8 @@ public async Task<ListBankingAccountBalancesResponse> ListAsync(ListBankingAccou
107103
108104 Func < Task < HttpResponseMessage > > retrySend = async ( ) =>
109105 {
110- var _httpRequest = await _client . CloneAsync ( httpRequest ) ;
111- return await _client . SendAsync ( _httpRequest ) ;
106+ var _httpRequest = await SDKConfiguration . Client . CloneAsync ( httpRequest ) ;
107+ return await SDKConfiguration . Client . SendAsync ( _httpRequest ) ;
112108 } ;
113109 var retries = new Codat . Lending . Utils . Retries . Retries ( retrySend , retryConfig , statusCodes ) ;
114110
@@ -148,7 +144,17 @@ public async Task<ListBankingAccountBalancesResponse> ListAsync(ListBankingAccou
148144 {
149145 if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
150146 {
151- var obj = ResponseBodyDeserializer . Deserialize < BankingAccountBalances > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
147+ var httpResponseBody = await httpResponse . Content . ReadAsStringAsync ( ) ;
148+ BankingAccountBalances obj ;
149+ try
150+ {
151+ obj = ResponseBodyDeserializer . DeserializeNotNull < BankingAccountBalances > ( httpResponseBody , NullValueHandling . Ignore ) ;
152+ }
153+ catch ( Exception ex )
154+ {
155+ throw new ResponseValidationException ( "Failed to deserialize response body into BankingAccountBalances." , httpResponse , httpResponseBody , ex ) ;
156+ }
157+
152158 var response = new ListBankingAccountBalancesResponse ( )
153159 {
154160 StatusCode = responseStatusCode ,
@@ -159,24 +165,58 @@ public async Task<ListBankingAccountBalancesResponse> ListAsync(ListBankingAccou
159165 return response ;
160166 }
161167
162- throw new Models . Errors . SDKException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
168+ throw new Models . Errors . SDKException ( "Unknown content type received" , httpResponse , await httpResponse . Content . ReadAsStringAsync ( ) ) ;
169+ }
170+ else if ( new List < int > { 400 , 401 , 402 , 403 , 404 , 409 , 429 } . Contains ( responseStatusCode ) )
171+ {
172+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
173+ {
174+ var httpResponseBody = await httpResponse . Content . ReadAsStringAsync ( ) ;
175+ ErrorMessagePayload payload ;
176+ try
177+ {
178+ payload = ResponseBodyDeserializer . DeserializeNotNull < ErrorMessagePayload > ( httpResponseBody , NullValueHandling . Ignore ) ;
179+ }
180+ catch ( Exception ex )
181+ {
182+ throw new ResponseValidationException ( "Failed to deserialize response body into ErrorMessagePayload." , httpResponse , httpResponseBody , ex ) ;
183+ }
184+
185+ throw new ErrorMessage ( payload , httpResponse , httpResponseBody ) ;
186+ }
187+
188+ throw new Models . Errors . SDKException ( "Unknown content type received" , httpResponse , await httpResponse . Content . ReadAsStringAsync ( ) ) ;
163189 }
164- else if ( new List < int > { 400 , 401 , 402 , 403 , 404 , 409 , 429 , 500 , 503 } . Contains ( responseStatusCode ) )
190+ else if ( new List < int > { 500 , 503 } . Contains ( responseStatusCode ) )
165191 {
166192 if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
167193 {
168- var obj = ResponseBodyDeserializer . Deserialize < ErrorMessage > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
169- throw obj ! ;
194+ var httpResponseBody = await httpResponse . Content . ReadAsStringAsync ( ) ;
195+ ErrorMessagePayload payload ;
196+ try
197+ {
198+ payload = ResponseBodyDeserializer . DeserializeNotNull < ErrorMessagePayload > ( httpResponseBody , NullValueHandling . Ignore ) ;
199+ }
200+ catch ( Exception ex )
201+ {
202+ throw new ResponseValidationException ( "Failed to deserialize response body into ErrorMessagePayload." , httpResponse , httpResponseBody , ex ) ;
203+ }
204+
205+ throw new ErrorMessage ( payload , httpResponse , httpResponseBody ) ;
170206 }
171207
172- throw new Models . Errors . SDKException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
208+ throw new Models . Errors . SDKException ( "Unknown content type received" , httpResponse , await httpResponse . Content . ReadAsStringAsync ( ) ) ;
209+ }
210+ else if ( responseStatusCode >= 400 && responseStatusCode < 500 )
211+ {
212+ throw new Models . Errors . SDKException ( "API error occurred" , httpResponse , await httpResponse . Content . ReadAsStringAsync ( ) ) ;
173213 }
174- else if ( responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600 )
214+ else if ( responseStatusCode >= 500 && responseStatusCode < 600 )
175215 {
176- throw new Models . Errors . SDKException ( "API error occurred" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
216+ throw new Models . Errors . SDKException ( "API error occurred" , httpResponse , await httpResponse . Content . ReadAsStringAsync ( ) ) ;
177217 }
178218
179- throw new Models . Errors . SDKException ( "Unknown status code received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
219+ throw new Models . Errors . SDKException ( "Unknown status code received" , httpResponse , await httpResponse . Content . ReadAsStringAsync ( ) ) ;
180220 }
181221 }
182222}
0 commit comments