11
11
namespace DingSDK
12
12
{
13
13
using DingSDK . Models . Components ;
14
+ using DingSDK . Models . Errors ;
14
15
using DingSDK . Models . Requests ;
15
16
using DingSDK . Utils ;
16
17
using Newtonsoft . Json ;
18
+ using System . Collections . Generic ;
17
19
using System . Net . Http . Headers ;
18
20
using System . Net . Http ;
19
21
using System . Threading . Tasks ;
@@ -38,10 +40,10 @@ public class Lookup: ILookup
38
40
{
39
41
public SDKConfig SDKConfiguration { get ; private set ; }
40
42
private const string _language = "csharp" ;
41
- private const string _sdkVersion = "0.12 .0" ;
42
- private const string _sdkGenVersion = "2.292.0 " ;
43
+ private const string _sdkVersion = "0.13 .0" ;
44
+ private const string _sdkGenVersion = "2.295.1 " ;
43
45
private const string _openapiDocVersion = "1.0.0" ;
44
- private const string _userAgent = "speakeasy-sdk/csharp 0.12 .0 2.292.0 1.0.0 DingSDK" ;
46
+ private const string _userAgent = "speakeasy-sdk/csharp 0.13 .0 2.295.1 1.0.0 DingSDK" ;
45
47
private string _serverUrl = "" ;
46
48
private ISpeakeasyHttpClient _defaultClient ;
47
49
private Func < Security > ? _securitySource ;
@@ -77,32 +79,46 @@ public Lookup(ISpeakeasyHttpClient defaultClient, Func<Security>? securitySource
77
79
var httpResponse = await client . SendAsync ( httpRequest ) ;
78
80
79
81
var contentType = httpResponse . Content . Headers . ContentType ? . MediaType ;
80
-
81
82
var response = new Models . Requests . LookupResponse
82
83
{
83
84
StatusCode = ( int ) httpResponse . StatusCode ,
84
85
ContentType = contentType ,
85
86
RawResponse = httpResponse
86
87
} ;
87
-
88
- if ( ( response . StatusCode == 200 ) )
88
+ if ( response . StatusCode == 200 )
89
89
{
90
90
if ( Utilities . IsContentTypeMatch ( "application/json" , response . ContentType ) )
91
+ {
92
+ var obj = ResponseBodyDeserializer . Deserialize < Models . Components . LookupResponse > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
93
+ response . LookupResponseValue = obj ;
94
+ }
95
+ else
91
96
{
92
- response . LookupResponseValue = JsonConvert . DeserializeObject < Models . Components . LookupResponse > ( await httpResponse . Content . ReadAsStringAsync ( ) , new JsonSerializerSettings ( ) { NullValueHandling = NullValueHandling . Ignore , Converters = new JsonConverter [ ] { new FlexibleObjectDeserializer ( ) , new EnumConverter ( ) , new AnyDeserializer ( ) } } ) ;
97
+ throw new SDKException ( "API error occurred" , ( int ) httpResponse . StatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
93
98
}
94
99
95
- return response ;
96
100
}
97
-
98
- if ( ( response . StatusCode == 400 ) )
101
+ else if ( response . StatusCode == 400 )
99
102
{
100
103
if ( Utilities . IsContentTypeMatch ( "application/json" , response . ContentType ) )
104
+ {
105
+ var obj = ResponseBodyDeserializer . Deserialize < ErrorResponse > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
106
+ throw obj ! ;
107
+ }
108
+ else
101
109
{
102
- response . ErrorResponse = JsonConvert . DeserializeObject < ErrorResponse > ( await httpResponse . Content . ReadAsStringAsync ( ) , new JsonSerializerSettings ( ) { NullValueHandling = NullValueHandling . Ignore , Converters = new JsonConverter [ ] { new FlexibleObjectDeserializer ( ) , new EnumConverter ( ) , new AnyDeserializer ( ) } } ) ;
110
+ throw new SDKException ( "API error occurred" , ( int ) httpResponse . StatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
103
111
}
104
112
105
- return response ;
113
+ }
114
+ else if ( response . StatusCode >= 400 && response . StatusCode < 500 || response . StatusCode >= 500 && response . StatusCode < 600 )
115
+ {
116
+ throw new SDKException ( "API error occurred" , ( int ) httpResponse . StatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
117
+
118
+ }
119
+ else
120
+ {
121
+ throw new SDKException ( "unknown status code received" , ( int ) httpResponse . StatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
106
122
}
107
123
return response ;
108
124
}
0 commit comments