@@ -51,47 +51,51 @@ private void HandleException(Exception exception)
51
51
ErrorCategory targetErrorCategory = ErrorCategory . NotSpecified ;
52
52
var graphEx = exception as GraphErrorException ;
53
53
54
- if ( graphEx ! = null )
54
+ if ( graphEx = = null )
55
55
{
56
- if ( graphEx . Body != null && graphEx . Body . Message != null && graphEx . Body . Code != null )
56
+ throw exception ;
57
+ }
58
+
59
+ if ( graphEx . Body != null && graphEx . Body . Message != null && graphEx . Body . Code != null )
60
+ {
61
+ WriteDebug ( String . Format ( ProjectResources . GraphException , graphEx . Body . Code , graphEx . Body . Message ) ) ;
62
+ targetEx = new Exception ( graphEx . Body . Message ) ;
63
+ targetErrorId = graphEx . Body . Code ;
64
+ }
65
+ else
66
+ {
67
+ if ( graphEx . Response != null && graphEx . Response . StatusCode == HttpStatusCode . NotFound )
57
68
{
58
- WriteDebug ( String . Format ( ProjectResources . GraphException , graphEx . Body . Code , graphEx . Body . Message ) ) ;
59
- targetEx = new Exception ( graphEx . Body . Message ) ;
60
- targetErrorId = graphEx . Body . Code ;
69
+ targetErrorCategory = ErrorCategory . InvalidArgument ;
61
70
}
62
71
else
63
72
{
64
- if ( graphEx . Response != null && graphEx . Response . StatusCode == HttpStatusCode . NotFound )
65
- {
66
- targetErrorCategory = ErrorCategory . InvalidArgument ;
67
- }
68
- else
69
- {
70
- targetErrorCategory = ErrorCategory . InvalidOperation ;
71
- }
72
- Exception parsedException = ParseResponse ( graphEx ) ;
73
- targetEx = parsedException != null ? parsedException : targetEx ;
73
+ targetErrorCategory = ErrorCategory . InvalidOperation ;
74
74
}
75
- var errorRecord = new ErrorRecord ( targetEx , targetErrorId , targetErrorCategory , null ) ;
76
- WriteError ( errorRecord ) ;
77
- }
78
- else
79
- {
80
- throw exception ;
75
+
76
+ Exception parsedException = ParseResponse ( graphEx ) ;
77
+ targetEx = parsedException ?? targetEx ;
81
78
}
79
+
80
+ var errorRecord = new ErrorRecord ( targetEx , targetErrorId , targetErrorCategory , null ) ;
81
+ WriteError ( errorRecord ) ;
82
82
}
83
83
84
84
85
85
private Exception ParseResponse ( GraphErrorException graphEx )
86
86
{
87
- int exceptionMessageIndex = graphEx . Response . Content . IndexOf ( "\" value\" :" , StringComparison . CurrentCultureIgnoreCase ) ;
88
- if ( exceptionMessageIndex > 0 )
87
+ if ( graphEx ? . Response ? . Content != null )
89
88
{
90
- string substring = graphEx . Response . Content . Substring ( exceptionMessageIndex + 9 ) ;
91
- // the start index is added 9, so as to remove the delimiter \"value\":\
92
- string exceptionDetails = substring . Substring ( 0 , substring . IndexOf ( "\" }" ) ) ;
93
- return new Exception ( exceptionDetails ) ;
89
+ int exceptionMessageIndex = graphEx . Response . Content . IndexOf ( "\" value\" :" , StringComparison . CurrentCultureIgnoreCase ) ;
90
+ if ( exceptionMessageIndex > 0 )
91
+ {
92
+ string substring = graphEx . Response . Content . Substring ( exceptionMessageIndex + 9 ) ;
93
+ // the start index is added 9, so as to remove the delimiter \"value\":\
94
+ string exceptionDetails = substring . Substring ( 0 , substring . IndexOf ( "\" }" ) ) ;
95
+ return new Exception ( exceptionDetails ) ;
96
+ }
94
97
}
98
+
95
99
return null ;
96
100
}
97
101
0 commit comments