File tree Expand file tree Collapse file tree
gax-java/gax-httpjson/src
main/java/com/google/api/gax/httpjson
test/java/com/google/api/gax/httpjson Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -101,6 +101,10 @@ static ErrorDetails parseErrorDetails(String errorJson) {
101101 }
102102
103103 JsonElement errorElement = root .get ("error" );
104+ if (!errorElement .isJsonObject ()) {
105+ return ErrorDetails .builder ().build ();
106+ }
107+
104108 Status .Builder statusBuilder = Status .newBuilder ();
105109 JSON_PARSER .merge (errorElement .toString (), statusBuilder );
106110 Status status = statusBuilder .build ();
Original file line number Diff line number Diff line change @@ -111,14 +111,12 @@ void parseErrorDetails_noDetails() {
111111 @ Test
112112 void parseErrorDetails_garbageInError () {
113113 String payload = "{\" error\" : \" not-an-object\" }" ;
114- Assertions .assertThrows (
115- RuntimeException .class , () -> HttpJsonErrorParser .parseErrorDetails (payload ));
114+ assertThat (HttpJsonErrorParser .parseErrorDetails (payload ).getErrorInfo ()).isNull ();
116115 }
117116
118117 @ Test
119118 void parseErrorDetails_arrayInError () {
120119 String payload = "{\" error\" : []}" ;
121- Assertions .assertThrows (
122- RuntimeException .class , () -> HttpJsonErrorParser .parseErrorDetails (payload ));
120+ assertThat (HttpJsonErrorParser .parseErrorDetails (payload ).getErrorInfo ()).isNull ();
123121 }
124122}
You can’t perform that action at this time.
0 commit comments