diff --git a/internal/globalservice/event_api.go b/internal/globalservice/event_api.go index b31ffb9..dc227bb 100644 --- a/internal/globalservice/event_api.go +++ b/internal/globalservice/event_api.go @@ -47,7 +47,7 @@ func (srv *GlobalService) GetTotalSharedCatalogs() (uint64, error) { return srv.countFilteredEvents(subject) } -// Retrieves the most recent bound context by loading the account projection +// Retrieves the most recent bound context by loading the account projection, if any func (srv *GlobalService) GetBoundContext(myAccountKey string) (*models.ContextBoundEvent, error) { js, _ := jetstream.New(srv.nc) ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) @@ -62,6 +62,9 @@ func (srv *GlobalService) GetBoundContext(myAccountKey string) (*models.ContextB slog.Error("Failed to load source account for catalog query", slog.Any("error", err)) return nil, err } + if myAccount == nil { + return nil, nil + } return myAccount.BoundContext, nil } @@ -71,6 +74,9 @@ func (srv *GlobalService) GetOAuthIdForAccount(accountKey string) (*string, erro if err != nil { return nil, err } + if discoveredContext == nil { + return nil, nil + } return &discoveredContext.OAuthIdentity, nil } diff --git a/internal/globalservice/hb.go b/internal/globalservice/hb.go index 420283c..f475c86 100644 --- a/internal/globalservice/hb.go +++ b/internal/globalservice/hb.go @@ -13,7 +13,7 @@ import ( func handleHeartbeat(srv *GlobalService) func(m *nats.Msg) { return func(m *nats.Msg) { accountKey := extractAccountKey(m.Subject) - slog.Info("Receiving heartbeat", slog.String("account", accountKey)) + slog.Debug("Receiving heartbeat", slog.String("account", accountKey)) var hb models.Heartbeat err := json.Unmarshal(m.Data, &hb) if err != nil { diff --git a/internal/globalservice/whoami.go b/internal/globalservice/whoami.go index 5995cd1..e29791a 100644 --- a/internal/globalservice/whoami.go +++ b/internal/globalservice/whoami.go @@ -31,13 +31,9 @@ func handleWhoAmi(srv *GlobalService) func(m *nats.Msg) { return } - // Note: a non-error but nil oauth is valid - just means it hasn't been context - // bound yet - oauth, err := srv.GetOAuthIdForAccount(accountKey) - if err != nil { - slog.Error("Failed to query OAuth ID for account", err) - _ = m.Respond(models.NewApiResultFail("Internal server error", 500)) - return + var oauth *string + if act.BoundContext != nil && len(act.BoundContext.OAuthIdentity) > 0 { + oauth = &act.BoundContext.OAuthIdentity } resp := models.WhoamiResponse{