@@ -61,7 +61,7 @@ void parseStatus_success() {
6161
6262 com .google .rpc .Status status = HttpJsonErrorParser .parseStatus (payload );
6363 assertThat (status ).isNotNull ();
64- assertThat (status .getCode ()).isEqualTo (16 );
64+ assertThat (status .getCode ()).isEqualTo (401 );
6565 assertThat (status .getMessage ())
6666 .isEqualTo ("Request is missing required authentication credential." );
6767
@@ -135,40 +135,4 @@ void parseStatus_arrayInError() {
135135 assertThat (HttpJsonErrorParser .parseStatus (payload ))
136136 .isEqualTo (com .google .rpc .Status .getDefaultInstance ());
137137 }
138- }
139- @ Test
140- void parseStatus_withHttpCodeAndGrpcStatusString () {
141- // AIP-193 standard JSON mapping typically includes the HTTP code in "code"
142- // and the gRPC status string in "status". Let's verify what JsonFormat actually extracts
143- // to the `com.google.rpc.Status` proto when both are present.
144- String payload =
145- "{\n "
146- + " \" error\" : {\n "
147- + " \" code\" : 403,\n "
148- + " \" status\" : \" PERMISSION_DENIED\" ,\n "
149- + " \" message\" : \" The caller does not have permission\" \n "
150- + " }\n "
151- + "}" ;
152-
153- com .google .rpc .Status status = HttpJsonErrorParser .parseStatus (payload );
154-
155- // In Protobuf, com.google.rpc.Status ONLY has `int32 code = 1;` and `string message = 2;`
156- // It does NOT have a `status` field. Because we use `.ignoringUnknownFields()` in the parser,
157- // the "status": "PERMISSION_DENIED" string is completely thrown away natively.
158- // However, our parser manually intercepts the 'status' string to override the gRPC integer.
159- // So we expect 7 (PERMISSION_DENIED), not 403!
160- assertThat (status .getCode ()).isEqualTo (7 );
161- assertThat (status .getMessage ()).isEqualTo ("The caller does not have permission" );
162- }
163-
164- @ Test
165- void parseStatus_withOnlyStatusString () {
166- String payload = "{\n " + " \" error\" : {\n " + " \" status\" : \" NOT_FOUND\" \n " + " }\n " + "}" ;
167-
168- com .google .rpc .Status status = HttpJsonErrorParser .parseStatus (payload );
169-
170- // Because "code" is missing, JsonFormat sets it to 0 (OK). But our manual override
171- // sees "status": "NOT_FOUND" and correctly maps it to 5.
172- assertThat (status .getCode ()).isEqualTo (5 );
173- }
174138}
0 commit comments