File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ namespace Tesla.NET.Requests
77 using System . Collections . Generic ;
88 using System . IO ;
99 using System . Linq ;
10+ using System . Net ;
1011 using System . Net . Http ;
1112 using System . Net . Http . Headers ;
1213 using System . Threading ;
@@ -412,10 +413,20 @@ private static async Task<IMessageResponse<T>> ReadFailureResponseAsync<T>(
412413 if ( responseMessage == null )
413414 throw new ArgumentNullException ( nameof ( responseMessage ) ) ;
414415
415- JObject rawJson =
416- IsContentJson ( responseMessage )
417- ? await ReadJsonAsync ( responseMessage , cancellationToken ) . ConfigureAwait ( false )
418- : null ;
416+ JObject rawJson = null ;
417+ try
418+ {
419+ // Check the content is JSON, and the response was not Unauthorized as the API returns a Content-Type
420+ // of application/json, but not JSON content.
421+ rawJson =
422+ IsContentJson ( responseMessage ) && responseMessage . StatusCode != HttpStatusCode . Unauthorized
423+ ? await ReadJsonAsync ( responseMessage , cancellationToken ) . ConfigureAwait ( false )
424+ : null ;
425+ }
426+ catch
427+ {
428+ // ignored to allow the error code to be returned.
429+ }
419430
420431 IMessageResponse < T > response = new MessageResponse < T > ( responseMessage . StatusCode , rawJson ) ;
421432 return response ;
You can’t perform that action at this time.
0 commit comments