@@ -182,9 +182,8 @@ public async Task<bool> LoginAsync(string server, string loginName, string usern
182182 /// <param name="id">Identifier for the request</param>
183183 /// <param name="ct">Cancellation token</param>
184184 /// <returns>Task for the proccess</returns>
185- /// <exception cref="HttpRequestException">There was an error while the request</exception>
186185 /// <exception cref="ObjectDisposedException">Thrown when the object is disposed</exception>
187- public async Task LogoutAsync ( string id = "getStudents " , CancellationToken ct = default )
186+ public async Task LogoutAsync ( string id = "Logout " , CancellationToken ct = default )
188187 {
189188 // Check for disposing
190189 if ( _disposedValue )
@@ -205,17 +204,13 @@ public async Task LogoutAsync(string id = "getStudents", CancellationToken ct =
205204 requestContent . Headers . Add ( "jsessionid" , _sessonId ) ;
206205
207206 // Send request
208- HttpResponseMessage response = await _client . PostAsync ( ServerUrl + "/WebUntis/jsonrpc.do" , requestContent , ct ) ;
207+ _ = await _client . PostAsync ( ServerUrl + "/WebUntis/jsonrpc.do" , requestContent , ct ) ;
209208
210209 // Clear data
211210 _serverUrl = null ;
212211 _loginName = null ;
213212 _sessonId = null ;
214213 _loggedIn = false ;
215-
216- // Verify response
217- if ( response . StatusCode != HttpStatusCode . OK )
218- throw new HttpRequestException ( $ "There was an error while the http request (Code: { response . StatusCode } ).") ;
219214 }
220215
221216 /// <summary>
@@ -287,7 +282,12 @@ private async Task<TResult> MakeJSONRPCRequestAsync<TRequest, TResult>(string id
287282
288283 // Check for WebUntis error
289284 if ( responseModel . Error != null )
285+ {
286+ if ( responseModel . Error . Code == ( int ) WebUntisException . Codes . NotAuthticated ) // Logout when not authenticated
287+ _ = LogoutAsync ( ) ;
288+
290289 throw responseModel . Error ;
290+ }
291291
292292 return responseModel . Result ;
293293 }
0 commit comments