File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -377,7 +377,7 @@ private static async Task<string> GetAccessTokenWithFederatedTokenAsync(string c
377377 {
378378 try
379379 {
380- Framework . Diagnostics . Log . Debug ( "TokenHandler" , "Retrieving Entra ID access Token with federated token..." ) ;
380+ Framework . Diagnostics . Log . Debug ( "TokenHandler" , "Retrieving Entra ID access token with federated token..." ) ;
381381 var httpClient = Framework . Http . PnPHttpClient . Instance . GetHttpClient ( ) ;
382382
383383 var queryParams = new List < string >
@@ -398,16 +398,20 @@ private static async Task<string> GetAccessTokenWithFederatedTokenAsync(string c
398398 request . Headers . Add ( "x-anonymous" , "true" ) ;
399399
400400 var response = await httpClient . SendAsync ( request ) ;
401- response . EnsureSuccessStatusCode ( ) ;
402401
403402 var responseContent = await response . Content . ReadAsStringAsync ( ) ;
403+ if ( ! response . IsSuccessStatusCode )
404+ {
405+ throw new HttpRequestException ( $ "Failed to retrieve federated access token: HTTP Error { response . StatusCode } : { responseContent } ") ;
406+ }
404407 var tokenResponse = JsonSerializer . Deserialize < Dictionary < string , object > > ( responseContent ) ;
405408
406409 return tokenResponse [ "access_token" ] . ToString ( ) ;
407410 }
408411 catch ( Exception ex )
409412 {
410- throw new PSInvalidOperationException ( $ "Failed to retrieve access token with federated token: { ex . Message } ", ex ) ;
413+ Framework . Diagnostics . Log . Error ( "TokenHandler" , ex . Message ) ;
414+ throw new PSInvalidOperationException ( ex . Message , ex ) ;
411415 }
412416 }
413417 }
You can’t perform that action at this time.
0 commit comments