File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
main/java/com/amadeus/exceptions Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,9 @@ private static StringBuffer getErrorsDescription(Response response) {
9090 message .append (String .format ("[%s] " , source .get ("parameter" ).getAsString ()));
9191 }
9292 }
93- message .append (String .format ("%s" , json .get ("detail" ).getAsString ()));
93+ if (json .has ("detail" ) && !json .get ("detail" ).isJsonNull ()) {
94+ message .append (String .format ("%s" , json .get ("detail" ).getAsString ()));
95+ }
9496 }
9597 return message ;
9698 }
Original file line number Diff line number Diff line change @@ -152,4 +152,17 @@ public class ExceptionsTest {
152152 assertTrue (new ParserException (null ) instanceof ResponseException );
153153 assertTrue (new ServerException (null ) instanceof ResponseException );
154154 }
155+
156+ @ Test public void testForErrorsWithoutDetail () {
157+ Response response = mock (Response .class );
158+ when (response .getStatusCode ()).thenReturn (401 );
159+ String body = "{\" errors\" :[{}]}" ;
160+ JsonObject json = new JsonParser ().parse (body ).getAsJsonObject ();
161+ when (response .getResult ()).thenReturn (json );
162+ when (response .isParsed ()).thenReturn (true );
163+
164+ ResponseException error = new ResponseException (response );
165+ assertEquals (error .toString (), "com.amadeus.exceptions.ResponseException: [401]"
166+ + "\n " );
167+ }
155168}
You can’t perform that action at this time.
0 commit comments