Skip to content

Commit

Permalink
[OGE-5650] Return not found status code
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalo-rodrigues committed Nov 2, 2023
1 parent 2a68324 commit 70cdb97
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func (h *Headscale) Serve() error {
}

// Start the local gRPC server without TLS and without authentication
grpcSocket := grpc.NewServer(zerolog.UnaryInterceptor())
grpcSocket := grpc.NewServer(zerolog.UnaryInterceptor(), grpc.UnaryInterceptor(serverErrorInterceptor))

v1.RegisterHeadscaleServiceServer(grpcSocket, newHeadscaleV1APIServer(h))
reflection.Register(grpcSocket)
Expand Down Expand Up @@ -991,3 +991,13 @@ func readOrCreatePrivateKey(path string) (*key.MachinePrivate, error) {

return &machineKey, nil
}

func serverErrorInterceptor(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
resp, err := handler(ctx, req)

if errors.Is(err, gorm.ErrRecordNotFound) {
return resp, status.Error(codes.NotFound, err.Error())
}

return resp, err
}

0 comments on commit 70cdb97

Please sign in to comment.