@@ -44,52 +44,41 @@ public ErrorResponse()
4444 /// </summary>
4545 /// <param name="responseValue">A <see cref="Dictionary{K, V}"/> containing names and values of
4646 /// the properties of this <see cref="ErrorResponse"/>.</param>
47- public ErrorResponse ( Dictionary < string , object > ? responseValue )
47+ public ErrorResponse ( Dictionary < string , object ? > ? responseValue )
4848 {
4949 if ( responseValue != null )
5050 {
51- if ( responseValue . ContainsKey ( "message" ) )
51+ if ( responseValue . TryGetValue ( "message" , out object ? messageObj )
52+ && messageObj ? . ToString ( ) is string message )
5253 {
53- if ( responseValue [ "message" ] != null )
54- {
55- this . message = responseValue [ "message" ] . ToString ( ) ?? "" ;
56- }
57- else
58- {
59- this . message = "The error did not contain a message." ;
60- }
54+ this . message = message ;
6155 }
62-
63- if ( responseValue . ContainsKey ( "screen" ) && responseValue [ "screen" ] != null )
56+ else
6457 {
65- this . screenshot = responseValue [ "screen" ] . ToString ( ) ?? " ";
58+ this . message = "The error did not contain a message. ";
6659 }
6760
68- if ( responseValue . ContainsKey ( "class" ) && responseValue [ "class" ] != null )
61+ if ( responseValue . TryGetValue ( "screen" , out object ? screenObj )
62+ && screenObj ? . ToString ( ) is string screen )
6963 {
70- this . className = responseValue [ "class" ] . ToString ( ) ?? "" ;
64+ this . screenshot = screen ;
7165 }
7266
73- if ( responseValue . ContainsKey ( "stackTrace" ) || responseValue . ContainsKey ( "stacktrace" ) )
67+ if ( responseValue . TryGetValue ( "class" , out object ? classObj )
68+ && classObj ? . ToString ( ) is string @class )
7469 {
75- object [ ] ? stackTraceArray = null ;
76-
77- if ( responseValue . ContainsKey ( "stackTrace" ) )
78- {
79- stackTraceArray = responseValue [ "stackTrace" ] as object [ ] ;
80- }
81- else if ( responseValue . ContainsKey ( "stacktrace" ) )
82- {
83- stackTraceArray = responseValue [ "stacktrace" ] as object [ ] ;
84- }
70+ this . className = @class ;
71+ }
8572
86- if ( stackTraceArray != null )
73+ if ( responseValue . TryGetValue ( "stackTrace" , out object ? stackTraceObj )
74+ || responseValue . TryGetValue ( "stacktrace" , out stackTraceObj ) )
75+ {
76+ if ( stackTraceObj is object ? [ ] stackTraceArray )
8777 {
8878 List < StackTraceElement > stackTraceList = new List < StackTraceElement > ( ) ;
89- foreach ( object rawStackTraceElement in stackTraceArray )
79+ foreach ( object ? rawStackTraceElement in stackTraceArray )
9080 {
91- Dictionary < string , object > ? elementAsDictionary = rawStackTraceElement as Dictionary < string , object > ;
92- if ( elementAsDictionary != null )
81+ if ( rawStackTraceElement is Dictionary < string , object ? > elementAsDictionary )
9382 {
9483 stackTraceList . Add ( new StackTraceElement ( elementAsDictionary ) ) ;
9584 }
0 commit comments