16
16
17
17
package org .springframework .graphql .client ;
18
18
19
- import java .math .BigInteger ;
20
19
import java .util .Collections ;
21
20
import java .util .List ;
22
21
import java .util .Map ;
23
- import java .util .Objects ;
24
22
import java .util .stream .Collectors ;
25
23
26
24
import graphql .ErrorClassification ;
@@ -125,29 +123,28 @@ private static final class MapResponseError implements ResponseError {
125
123
MapResponseError (Map <String , Object > errorMap ) {
126
124
Assert .notNull (errorMap , "'errorMap' is required" );
127
125
this .errorMap = errorMap ;
128
- this .locations = initLocations (errorMap );
126
+ this .locations = initSourceLocations (errorMap );
129
127
this .path = initPath (errorMap );
130
128
}
131
129
132
130
@ SuppressWarnings ("unchecked" )
133
- private static List <SourceLocation > initLocations (Map <String , Object > errorMap ) {
134
- return (( List <Map <String , Object >>) errorMap .getOrDefault ("locations" , Collections . emptyList ())). stream ()
135
- . map ( map -> new SourceLocation (
136
- objectAsInt ( map . get ( "line" )),
137
- objectAsInt ( map . get ( "column" )),
138
- Objects . toString ( map . get ( "sourceName" ) )
139
- ))
131
+ private static List <SourceLocation > initSourceLocations (Map <String , Object > errorMap ) {
132
+ List < Map < String , Object >> locations = ( List <Map <String , Object >>) errorMap .get ("locations" );
133
+ if ( locations == null ) {
134
+ return Collections . emptyList ();
135
+ }
136
+ return locations . stream ( )
137
+ . map ( m -> new SourceLocation ( getInt ( m , "line" ), getInt ( m , "column" ), ( String ) m . get ( "sourceName" ) ))
140
138
.collect (Collectors .toList ());
141
139
}
142
140
143
- private static int objectAsInt (Object value ) {
144
-
145
- if (value instanceof BigInteger bigInteger ) {
146
- return bigInteger .intValue ();
147
- } else if (value instanceof Number number ) {
141
+ private static int getInt (Map <String , Object > map , String key ) {
142
+ if (map .get (key ) instanceof Number number ) {
148
143
return number .intValue ();
149
- } else {
150
- return -1 ;
144
+ }
145
+ else {
146
+ throw new IllegalArgumentException (
147
+ "Expected integer value: " + ObjectUtils .nullSafeClassName (map .get (key )));
151
148
}
152
149
}
153
150
@@ -162,6 +159,7 @@ private static String initPath(Map<String, Object> errorMap) {
162
159
(s , s2 ) -> null );
163
160
}
164
161
162
+
165
163
@ Override
166
164
@ Nullable
167
165
public String getMessage () {
0 commit comments