Skip to content

Commit

Permalink
Return Unimplemented when services or methods are not implemented
Browse files Browse the repository at this point in the history
gRPC has UNIMPLEMENTED status code that indicates a requested method
is not implemented. However ttrpc was returning codes.NotFound which
could be returned when a request entity was not there.

This fix changes the status code from codes.NotFound to
codes.Unimplemented to disambiguate and be more compatible with gRPC.

Fixes #80.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
  • Loading branch information
kzys committed May 21, 2021
1 parent 25f5476 commit fede9db
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestServer(t *testing.T) {
}
}

func TestServerNotFound(t *testing.T) {
func TestServerUnimplemented(t *testing.T) {
var (
ctx = context.Background()
server = mustServer(t)(NewServer())
Expand All @@ -155,7 +155,7 @@ func TestServerNotFound(t *testing.T) {
t.Fatalf("expected error from non-existent service call")
} else if status, ok := status.FromError(err); !ok {
t.Fatalf("expected status present in error: %v", err)
} else if status.Code() != codes.NotFound {
} else if status.Code() != codes.Unimplemented {
t.Fatalf("expected not found for method")
}

Expand Down
4 changes: 2 additions & 2 deletions services.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ func (s *serviceSet) dispatch(ctx context.Context, serviceName, methodName strin
func (s *serviceSet) resolve(service, method string) (Method, error) {
srv, ok := s.services[service]
if !ok {
return nil, status.Errorf(codes.NotFound, "service %v", service)
return nil, status.Errorf(codes.Unimplemented, "service %v", service)
}

mthd, ok := srv.Methods[method]
if !ok {
return nil, status.Errorf(codes.NotFound, "method %v", method)
return nil, status.Errorf(codes.Unimplemented, "method %v", method)
}

return mthd, nil
Expand Down

0 comments on commit fede9db

Please sign in to comment.