Skip to content

Commit

Permalink
clean up Update a tiny bit
Browse files Browse the repository at this point in the history
  • Loading branch information
JJTech0130 committed Jul 3, 2024
1 parent 509901e commit 619688a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ func cookiesFromMetadata(metadata map[string]interface{}) *cookies.Cookies {
func NewMetaClient(ctx context.Context, main *MetaConnector, login *bridgev2.UserLogin) (*MetaClient, error) {
cookies := cookiesFromMetadata(login.Metadata.Extra)
login.Metadata.Extra["cookies"] = cookies
err := login.Save(ctx)
if err != nil {
return nil, fmt.Errorf("failed to save cookies: %w", err)
}

log := login.User.Log.With().Str("component", "messagix").Logger()
client := messagix.NewClient(cookies, log)
Expand All @@ -56,12 +52,13 @@ func NewMetaClient(ctx context.Context, main *MetaConnector, login *bridgev2.Use
}, nil
}

func (m *MetaClient) Update(ctx context.Context) {
func (m *MetaClient) Update(ctx context.Context) error {
err := m.login.Save(ctx)
if err != nil {
m.log.Err(err).Msg("Failed to update cookies")
return fmt.Errorf("failed to save updated cookies: %w", err)
}
m.log.Debug().Msg("Updated cookies")
return nil
}

func (m *MetaClient) eventHandler(rawEvt any) {
Expand Down Expand Up @@ -159,7 +156,10 @@ func (m *MetaClient) Connect(ctx context.Context) error {
if err != nil {
return fmt.Errorf("failed to connect to messagix: %w", err)
}
m.Update(ctx)
err = m.Update(ctx)
if err != nil {
return err
}
return nil
}

Expand Down

0 comments on commit 619688a

Please sign in to comment.