Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

context.ResponseTrailers() not working? #562

Closed
AnthonyGiretti opened this issue Sep 30, 2019 · 3 comments · Fixed by #567
Closed

context.ResponseTrailers() not working? #562

AnthonyGiretti opened this issue Sep 30, 2019 · 3 comments · Fixed by #567
Assignees
Labels
bug Something isn't working
Milestone

Comments

@AnthonyGiretti
Copy link

AnthonyGiretti commented Sep 30, 2019

I'm building a gRPC service.
I try validate data I receive and reply with an error like this:

public override Task<IntroduceYourselfReply> IntroduceYourself(IntroduceYourselfRequest request, ServerCallContext context)
        {
            if (string.IsNullOrEmpty(request.Name))
            {
                context.ResponseTrailers.Add(new Metadata.Entry("Name","the value was empty"));
                context.Status = new Status(StatusCode.InvalidArgument, $"Validation failed");
                return Task.FromResult(new IntroduceYourselfReply());
            }
            
            return Task.FromResult(new IntroduceYourselfReply
            {
                Name = request.Name,
                Job = "Developer",
                Country = "Canada",
                Citizenship = { new string[] {"France", "Canada" } },
                Skills = { new Skill[] { new Skill { SkillName = ".NET", SkillLevel = SkillLevel.Good }, 
                                         new Skill { SkillName = "CSS", SkillLevel = SkillLevel.Bad } } 
                }
            });
        }

context.ResponseTrailers is supposed to be filled, but clientSide the property trailers is empty.
Filling the status works fine by the way.

Is this a bug or I'am using ResponseTrailers not correctly?

@JamesNK
Copy link
Member

JamesNK commented Sep 30, 2019

This is a bug. Currently the .NET gRPC client doesn't populate trailers into RpcException.Trailers. This will be fixed in a future version.

GetTrailers() does return the trailers. What you can do for now with a unary method:

var call = client.IntroduceYourselfAsync(new IntroduceYourselfRequest());

try
{
    var response = await call;
}
catch (RpcException)
{
    // Log?
}

var trailers = call.GetTrailers();

@JamesNK JamesNK self-assigned this Sep 30, 2019
@AnthonyGiretti
Copy link
Author

Thank you!

@JamesNK JamesNK added the bug Something isn't working label Oct 4, 2019
@JamesNK JamesNK added this to the vNext milestone Oct 7, 2019
@JamesNK
Copy link
Member

JamesNK commented Oct 7, 2019

Closing as duplicate

@JamesNK JamesNK closed this as completed Oct 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants