@@ -397,50 +397,47 @@ private static string FixPath(string path)
397397
398398 private async Task CheckResponse ( HttpResponseMessage response )
399399 {
400- if ( ! response . IsSuccessStatusCode )
400+ if ( response . IsSuccessStatusCode ) return ;
401+ try
401402 {
402- try
403+ var xml = await response . Content . ReadAsStringAsync ( ) ;
404+ if ( xml . Length > 0 )
403405 {
404- var xml = await response . Content . ReadAsStringAsync ( ) ;
405- if ( xml . Length > 0 )
406+ var doc = XDocument . Parse ( xml ) ;
407+ var code = doc . Descendants ( "ErrorCode" ) . FirstOrDefault ( ) ;
408+ var description = doc . Descendants ( "Description" ) . FirstOrDefault ( ) ;
409+ if ( code == null )
406410 {
407- var doc = XDocument . Parse ( xml ) ;
408- var code = doc . Descendants ( "ErrorCode" ) . FirstOrDefault ( ) ;
409- var description = doc . Descendants ( "Description" ) . FirstOrDefault ( ) ;
410- if ( code == null )
411+ var error = doc . Descendants ( "Error" ) . FirstOrDefault ( ) ;
412+ if ( error == null )
411413 {
412- var error = doc . Descendants ( "Error" ) . FirstOrDefault ( ) ;
413- if ( error == null )
414- {
415- var exceptions =
416- ( from item in doc . Descendants ( "Errors" )
417- select
418- ( Exception ) new BandwidthIrisException ( item . Element ( "Code" ) . Value ,
419- item . Element ( "Description" ) . Value , response . StatusCode ) ) . ToArray ( ) ;
420- if ( exceptions . Length > 0 )
421- {
422- throw new AggregateException ( exceptions ) ;
423- }
424- code = doc . Descendants ( "resultCode" ) . FirstOrDefault ( ) ;
425- description = doc . Descendants ( "resultMessage" ) . FirstOrDefault ( ) ;
426- }
427- else
414+ var exceptions =
415+ ( from item in doc . Descendants ( "Errors" )
416+ select
417+ ( Exception ) new BandwidthIrisException ( item . Element ( "Code" ) . Value ,
418+ item . Element ( "Description" ) . Value , response . StatusCode ) ) . ToArray ( ) ;
419+ if ( exceptions . Length > 0 )
428420 {
429- code = error . Element ( "Code" ) ;
430- description = error . Element ( "Description" ) ;
421+ throw new AggregateException ( exceptions ) ;
431422 }
423+ code = doc . Descendants ( "resultCode" ) . FirstOrDefault ( ) ;
424+ description = doc . Descendants ( "resultMessage" ) . FirstOrDefault ( ) ;
432425 }
433- if ( code != null && description != null && ! string . IsNullOrEmpty ( code . Value ) && code . Value != "0" )
426+ else
434427 {
435- throw new BandwidthIrisException ( code . Value , description . Value , response . StatusCode , doc ) ;
428+ code = error . Element ( "Code" ) ;
429+ description = error . Element ( "Description" ) ;
436430 }
437431 }
432+ if ( code != null && description != null && ! string . IsNullOrEmpty ( code . Value ) && code . Value != "0" )
433+ {
434+ throw new BandwidthIrisException ( code . Value , description . Value , response . StatusCode , doc ) ;
435+ }
438436 }
439- catch ( Exception ex ) when ( ! ( ex is BandwidthIrisException ) && ! ( ex is AggregateException ) )
440- {
441-
442- throw new BandwidthIrisException ( "" , string . Format ( "Http code {0}" , response . StatusCode ) , response . StatusCode ) ;
443- }
437+ }
438+ catch ( Exception ex ) when ( ! ( ex is BandwidthIrisException ) && ! ( ex is AggregateException ) )
439+ {
440+ throw new BandwidthIrisException ( "" , string . Format ( "Http code {0}" , response . StatusCode ) , response . StatusCode ) ;
444441 }
445442 }
446443
0 commit comments