Skip to content

Commit

Permalink
fix: rename healthcheckfailed error to errnotserving
Browse files Browse the repository at this point in the history
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
  • Loading branch information
rodneyosodo committed Jun 12, 2024
1 parent deab731 commit 4852b6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
16 changes: 5 additions & 11 deletions pkg/auth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
grpchealth "google.golang.org/grpc/health/grpc_health_v1"
)

var errHealthCheckFailed = errors.New("health check failed")
var errSvcNotServing = errors.New("service is not serving")

// Setup loads Auth gRPC configuration and creates new Auth gRPC client.
//
Expand All @@ -30,11 +30,8 @@ func Setup(ctx context.Context, cfg Config) (magistrala.AuthServiceClient, Handl
resp, err := health.Check(ctx, &grpchealth.HealthCheckRequest{
Service: "auth",
})
if err != nil {
return nil, nil, errors.Wrap(errHealthCheckFailed, err)
}
if resp.GetStatus() != grpchealth.HealthCheckResponse_SERVING {
return nil, nil, errors.Wrap(errHealthCheckFailed, errors.New("service is not serving"))
if err != nil || resp.GetStatus() != grpchealth.HealthCheckResponse_SERVING {
return nil, nil, errSvcNotServing
}

return authgrpc.NewClient(client.Connection(), cfg.Timeout), client, nil
Expand All @@ -55,11 +52,8 @@ func SetupAuthz(ctx context.Context, cfg Config) (magistrala.AuthzServiceClient,
resp, err := health.Check(ctx, &grpchealth.HealthCheckRequest{
Service: "things",
})
if err != nil {
return nil, nil, errors.Wrap(errHealthCheckFailed, err)
}
if resp.GetStatus() != grpchealth.HealthCheckResponse_SERVING {
return nil, nil, errors.Wrap(errHealthCheckFailed, errors.New("service is not serving"))
if err != nil || resp.GetStatus() != grpchealth.HealthCheckResponse_SERVING {
return nil, nil, errSvcNotServing
}

return thingsauth.NewClient(client.Connection(), cfg.Timeout), client, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/auth/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestSetupAuth(t *testing.T) {
URL: "",
Timeout: time.Second,
},
err: errors.New("health check failed"),
err: errors.New("service is not serving"),
},
}

Expand Down Expand Up @@ -109,7 +109,7 @@ func TestSetupAuthz(t *testing.T) {
URL: "",
Timeout: time.Second,
},
err: errors.New("health check failed"),
err: errors.New("service is not serving"),
},
}

Expand Down

0 comments on commit 4852b6b

Please sign in to comment.