user17508887
user17508887

Reputation: 57

How to get the status code within the response in grpcurl?

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"
}

Upvotes: 0

Views: 2201

Answers (1)

DazWilkin
DazWilkin

Reputation: 40366

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 .

Upvotes: 2

Related Questions