Skip to content

Should Request Handler set ResponseCode? #174

Open

Description

@siddjain

This is more of a question than an issue but I couldn't find another place to ask so asking it as an issue.

My question is that should a request handler be ever setting the ResponseCode?
https://github.com/uber/tchannel-java/blob/master/tchannel-core/src/main/java/com/uber/tchannel/api/ResponseCode.java

I looked at following two request handlers:
https://github.com/uber/tchannel-java/blob/master/tchannel-example/src/main/java/com/uber/tchannel/thrift/GetValueRequestHandler.java
https://github.com/uber/tchannel-java/blob/master/tchannel-example/src/main/java/com/uber/tchannel/thrift/SetValueRequestHandler.java

and notice that they do not set the ResponseCode. It seems to make sense. I suspect the ResponseCode is something that is set by tchannel (in case of an uncaught exception or network error) but just want to confirm.

Activity

  1. prashantv commented on Aug 25, 2017

    @prashantv

    If you trace through the builders used to create the Thrift response, you'll see it ends up at Response, which has a default value of OK:
    https://github.com/uber/tchannel-java/blob/master/tchannel-core/src/main/java/com/uber/tchannel/messages/Response.java#L250

  2. siddjain commented on Aug 25, 2017

    @siddjain
    Author

    this does not address the question. please re-read the question to understand what it is asking.

  3. yborovikov commented on Nov 22, 2017

    @yborovikov
    Contributor

    @siddjain, yes, the handler must set the response code for non-successful result responses.

    result.setSuccess(...);
    ThriftReponse response = new ThriftResponse
        .Builder<some_result>(request)
        .setResponseCode(ResponseCode.OK) // this is the default (so can be skipped; i don't)
        .setBody(result)
        .build();
    
    result.setMyDeclaredException(...);
    ThriftResponse response = new ThriftResponse
        .Builder<some_result>(request)
        .setResponseCode(ResponseCode.Error)
        .setBody(result)
        .build();
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions