Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nordigen): skip account on rate limit exceeded #87

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions reader/nordigen/nordigen.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nordigen

import (
"errors"
"fmt"
"log/slog"
"regexp"
Expand All @@ -10,6 +11,8 @@ import (
"github.com/martinohansen/ynabber"
)

const rateLimitExceededStatusCode = 429

type Reader struct {
Config *ynabber.Config
Client *nordigen.Client
Expand Down Expand Up @@ -75,13 +78,13 @@ func (r Reader) Bulk() (t []ynabber.Transaction, err error) {
return nil, fmt.Errorf("failed to authorize: %w", err)
}

r.logger.Info("bulk reading", "accounts", len(req.Accounts))
r.logger.Info("", "accounts", len(req.Accounts))
for _, account := range req.Accounts {
logger := r.logger.With("account", account)
accountMetadata, err := r.Client.GetAccountMetadata(account)
if err != nil {
return nil, fmt.Errorf("failed to get account metadata: %w", err)
}
logger := r.logger.With("iban", accountMetadata.Iban)

// Handle expired, or suspended accounts by recreating the
// requisition.
Expand All @@ -100,6 +103,11 @@ func (r Reader) Bulk() (t []ynabber.Transaction, err error) {
logger.Info("reading transactions")
transactions, err := r.Client.GetAccountTransactions(string(account.ID))
if err != nil {
var apiErr *nordigen.APIError
if errors.As(err, &apiErr) && apiErr.StatusCode == rateLimitExceededStatusCode {
logger.Warn("rate limit exceeded, skipping account")
continue
}
return nil, fmt.Errorf("failed to get transactions: %w", err)
}

Expand Down
Loading