0

I use grpcurl for grpc request. I have the following request:

grpcurl -plaintext -import-path C:/Users/username -proto file.proto <localhost:port > service_name/methode

The mentioned request will return the following response without the status code. How can I get the status code within the response?

{
  "id": "0000000000000",
  "name": "AAAAAAAAAA"
}
jps
  • 20,041
  • 15
  • 75
  • 79
user17508887
  • 57
  • 1
  • 7

1 Answers1

1

You cannot (directly).

Error codes are part of the gRPC protocol metadata not the (user-defined) message(s).

With gRPCurl, you've a couple of ways to get the error code.

In Bash, you can use command's exit status:

grpcurl ...
echo $?

See:

Or you can use gRPCurl's -format-error flag.

-format-error
        When a non-zero status is returned, format the response using the
        value set by the -format flag .
DazWilkin
  • 32,823
  • 5
  • 47
  • 88