1
1
using System . Net . Http . Headers ;
2
+ using System . Text ;
2
3
using System . Text . Json ;
3
4
using System . Text . Json . Serialization ;
4
5
using Sportradar . Mbs . Sdk . Exceptions ;
@@ -127,7 +128,7 @@ internal async Task<string> GetAuthTokenAsync(CancellationToken cancellationToke
127
128
128
129
var response = JsonSerializer . Deserialize < AuthResponse > ( content ) ;
129
130
if ( response == null || string . IsNullOrEmpty ( response . AccessToken ) )
130
- return null ;
131
+ return ProcessPossibleError ( response ) ;
131
132
132
133
var token = response . AccessToken . NotNull ( ) ;
133
134
if ( response . ExpiresIn is > 1 )
@@ -139,6 +140,27 @@ internal async Task<string> GetAuthTokenAsync(CancellationToken cancellationToke
139
140
return token ;
140
141
}
141
142
143
+ private string ? ProcessPossibleError ( AuthResponse ? authResponse )
144
+ {
145
+ if ( authResponse == null ) return null ;
146
+
147
+ if ( string . IsNullOrEmpty ( authResponse . Error ) && string . IsNullOrEmpty ( authResponse . ErrorDescription ) )
148
+ return null ;
149
+
150
+ var msg = new StringBuilder ( ) ;
151
+ msg . Append ( "Auth error" ) ;
152
+ if ( ! string . IsNullOrEmpty ( authResponse . Error ) )
153
+ {
154
+ msg . Append ( ": " ) . Append ( authResponse . Error . NotNull ( ) ) ;
155
+ }
156
+ if ( ! string . IsNullOrEmpty ( authResponse . ErrorDescription ) )
157
+ {
158
+ msg . Append ( ": " ) . Append ( authResponse . ErrorDescription . NotNull ( ) ) ;
159
+ }
160
+
161
+ throw new AuthTokenFailureException ( msg . ToString ( ) ) ;
162
+ }
163
+
142
164
public class AuthResponse
143
165
{
144
166
[ JsonPropertyName ( "access_token" ) ]
@@ -151,5 +173,9 @@ public class AuthResponse
151
173
public string ? RefreshToken { get ; set ; }
152
174
[ JsonPropertyName ( "scope" ) ]
153
175
public string ? Scope { get ; set ; }
176
+ [ JsonPropertyName ( "error" ) ]
177
+ public string ? Error { get ; set ; }
178
+ [ JsonPropertyName ( "error_description" ) ]
179
+ public string ? ErrorDescription { get ; set ; }
154
180
}
155
181
}
0 commit comments