Skip to content

Commit fede9db

Browse files
author
Kazuyoshi Kato
committed
Return Unimplemented when services or methods are not implemented
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 <[email protected]>
1 parent 25f5476 commit fede9db

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestServer(t *testing.T) {
136136
}
137137
}
138138

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

services.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ func (s *serviceSet) dispatch(ctx context.Context, serviceName, methodName strin
116116
func (s *serviceSet) resolve(service, method string) (Method, error) {
117117
srv, ok := s.services[service]
118118
if !ok {
119-
return nil, status.Errorf(codes.NotFound, "service %v", service)
119+
return nil, status.Errorf(codes.Unimplemented, "service %v", service)
120120
}
121121

122122
mthd, ok := srv.Methods[method]
123123
if !ok {
124-
return nil, status.Errorf(codes.NotFound, "method %v", method)
124+
return nil, status.Errorf(codes.Unimplemented, "method %v", method)
125125
}
126126

127127
return mthd, nil

0 commit comments

Comments
 (0)