From ca8ef209a73487bc135ec569a73b21fc53eef906 Mon Sep 17 00:00:00 2001 From: Random Guy <50927468+M03ED@users.noreply.github.com> Date: Sat, 19 Jul 2025 04:51:18 +0330 Subject: [PATCH] Stats API: Return status "not found" instead of "unknown" (#4860) --- app/stats/command/command.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/stats/command/command.go b/app/stats/command/command.go index 64e31d38..db5283c8 100644 --- a/app/stats/command/command.go +++ b/app/stats/command/command.go @@ -12,6 +12,8 @@ import ( "github.com/xtls/xray-core/core" feature_stats "github.com/xtls/xray-core/features/stats" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" ) // statsServer is an implementation of StatsService. @@ -30,7 +32,7 @@ func NewStatsServer(manager feature_stats.Manager) StatsServiceServer { func (s *statsServer) GetStats(ctx context.Context, request *GetStatsRequest) (*GetStatsResponse, error) { c := s.stats.GetCounter(request.Name) if c == nil { - return nil, errors.New(request.Name, " not found.") + return nil, status.Error(codes.NotFound, request.Name+" not found.") } var value int64 if request.Reset_ { @@ -49,7 +51,7 @@ func (s *statsServer) GetStats(ctx context.Context, request *GetStatsRequest) (* func (s *statsServer) GetStatsOnline(ctx context.Context, request *GetStatsRequest) (*GetStatsResponse, error) { c := s.stats.GetOnlineMap(request.Name) if c == nil { - return nil, errors.New(request.Name, " not found.") + return nil, status.Error(codes.NotFound, request.Name+" not found.") } value := int64(c.Count()) return &GetStatsResponse{ @@ -64,7 +66,7 @@ func (s *statsServer) GetStatsOnlineIpList(ctx context.Context, request *GetStat c := s.stats.GetOnlineMap(request.Name) if c == nil { - return nil, errors.New(request.Name, " not found.") + return nil, status.Error(codes.NotFound, request.Name+" not found.") } ips := make(map[string]int64)