This example demonstrates how to create and unpack detailed errors.
A command line tool that demonstrates how a detailed error can be thrown by a service and unpacked and inspected by a client. The detailed error model is described in more detailed in the gRPC Error Guide and is made available via the grpc-swift-protobuf package.
You must have the Protocol Buffers compiler (protoc
) installed. You can find
the instructions for doing this in the gRPC Swift Protobuf documentation.
The swift
commands below are all prefixed with PROTOC_PATH=$(which protoc)
,
this is to let the build system know where protoc
is located so that it can
generate stubs for you. You can read more about it in the gRPC Swift Protobuf
documentation.
Build and run the example using the CLI:
$ PROTOC_PATH=$(which protoc) swift run
Error code: resourceExhausted
Error message: The greeter has temporarily run out of greetings.
Error details:
- Localized message (en-GB): Out of enthusiasm. The greeter is having a cup of tea, try again after that.
- Localized message (en-US): Out of enthusiasm. The greeter is taking a coffee break, try again later.
- Help links:
- https://en.wikipedia.org/wiki/Caffeine (A Wikipedia page about caffeine including its properties and effects.)