@@ -64,7 +64,7 @@ protected async Task<TResult> GetAsync<TResult>(HttpMethod method, string path,
6464 var content = await response . Content . ReadAsStringAsync ( token ) ;
6565 this . Output . Verbose ( $ "Response body: { content } ") ;
6666
67- ValidateResponse ( response ) ;
67+ ValidateResponse ( response , content ) ;
6868
6969 try
7070 {
@@ -96,7 +96,7 @@ protected async Task SendAsync(HttpMethod method, string path, object body, Canc
9696 var content = await response . Content . ReadAsStringAsync ( token ) ;
9797 this . Output . Verbose ( $ "Response body: { content } ") ;
9898
99- ValidateResponse ( response ) ;
99+ ValidateResponse ( response , content ) ;
100100 }
101101
102102 protected async Task < TResult > SendAsync < TResult > ( HttpMethod method , string path , object body , CancellationToken token )
@@ -119,7 +119,7 @@ protected async Task<TResult> SendAsync<TResult>(HttpMethod method, string path,
119119 var content = await response . Content . ReadAsStringAsync ( token ) ;
120120 this . Output . Verbose ( $ "Response body: { content } ") ;
121121
122- ValidateResponse ( response ) ;
122+ ValidateResponse ( response , content ) ;
123123
124124 try
125125 {
@@ -160,10 +160,17 @@ private void LogRetry(HttpResponseMessage result, Exception exception, AttemptCo
160160 this . Output . Verbose ( $ "{ message } , retrying... [{ context . CurrentAttempt } . attempt, waiting { context . CurrentDelay } ]", ConsoleColor . Yellow ) ;
161161 }
162162
163- private static void ValidateResponse ( HttpResponseMessage responseMessage )
163+ private static void ValidateResponse ( HttpResponseMessage responseMessage , string content )
164164 {
165165 if ( ! responseMessage . IsSuccessStatusCode )
166+ {
167+ Dictionary < string , string [ ] > errorDetails ;
168+ try { errorDetails = JsonSerializer . Deserialize < Dictionary < string , string [ ] > > ( content ) ; }
169+ catch { errorDetails = null ; }
170+
166171 throw new HttpStatusException ( responseMessage . StatusCode ,
167- responseMessage . ReasonPhrase ) ;
172+ responseMessage . ReasonPhrase ,
173+ errorDetails ) ;
174+ }
168175 }
169176}
0 commit comments