0

I try to use gRPC-web with angular client and asp.netCore server side app. in server side when I throw a RpcException I could not access to Metadata or even error message on client side? is there any thing, I miss to implement?

private static async Task<RpcException> HandleRpcExceptionAsync<T>(RpcException exception, CallContext context, 
        ILogger<T> logger, 
        ILocalizationService localizationService, 
        IWorkContext workContext,
        Guid correlationId)
    {
        logger.LogError(exception, "CorrelationId: {CorrelationId} - An error occurred", correlationId);
        var trailers = exception.Trailers;
        trailers.Add(CreateTrailers(correlationId, exception.Message)[0]);
        return new RpcException(new Status(exception.StatusCode, exception.Message, exception), trailers, exception.Message);
    }

private static Metadata CreateTrailers(Guid correlationId,string errorMessage )
    {
        var trailers = new Metadata { { "CorrelationId", correlationId.ToString() }, {"errorMessage", "Test Farhad  Error"} };
        return trailers;
    } 

I try GrpcStatusEvent properties but allways I see GrpcMetadata with zero mapping (Map(0)), also try to add WithExposedHeaders("Grpc-Status", "Grpc-Message", "Grpc-Encoding", "Grpc- Accept-Encoding") but nothing happened

  • I think the problem is that grpc-web doesn't support "trailers" (a.k.a. trailing metadata). It does support initial metadata for responses though (so you need to set and check them instead). In the API they are referred to as "response headers" and not "response trailers". This is a limitation due the the protocol being used by grpc-web (HTTP1.1 doesn't support response trailers, unlike HTTP2 used by regular grpc). – Jan Tattermusch Jun 26 '23 at 09:54

0 Answers0