Missing grpc-status in onTrailer metadata
https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md
The provided document does not state that grpc-status must be present in gRPC trailer. It describes the way it is passed through HTTP2 header or trailer. In nice-grpc the status is manifested on a different level — via ClientError.code property.
via
ClientError.codeproperty.
This is a bit inconvenient, you need to write a lot of code when you could just read it in onTrailer. Do you think we can add this functionality?
Can you please provide an example of when it is more convenient to use the trailer than the exception?
Without
#debug: ClientMiddleware<ConnectionCallOptions> = async function* (this: Connection, call, options) {
try {
if (!call.responseStream) {
const response = yield* call.next(call.request, options);
return response;
} else {
for await (const response of call.next(call.request, options)) {
yield response;
}
return;
}
} catch (error) {
if (error instanceof ClientError) {
dbg.extend("grpc")('%s%s', this.address, error.message);
}
throw error;
}
}
With:
#debug: ClientMiddleware<ConnectionCallOptions> = async function* (this: Connection, call, options) {
return yield* call.next(call.request, {
...options,
onTrailer: (trailer) => {
dbg.extend("conn")('node id=%d address=%s status=%o', this.nodeId, this.address, trailer.get('grpc-status'));
},
})
}
This makes sense, but according to this doc the grpc-* headers are internal and are not exposed in gRPC metadata.
By the way, your example can be made shorter:
#debug: ClientMiddleware<ConnectionCallOptions> = async function* (this: Connection, call, options) {
try {
return yield* call.next(call.request, options);
} catch (error) {
if (error instanceof ClientError) {
dbg.extend("grpc")('%s%s', this.address, error.message);
}
throw error;
}
}
and are not exposed in gRPC metadata.
Some gRPC implementations expose grpc-*
Can you give examples of that?
https://github.com/connectrpc/connect-es https://www.npmjs.com/package/@connectrpc/connect