Skip to content

Commit

Permalink
handle account locked error correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
unkmonster committed Aug 24, 2024
1 parent 47765cb commit e70881c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
8 changes: 4 additions & 4 deletions downloading/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,12 @@ func BatchUserDownload(ctx context.Context, client *resty.Client, db *sqlx.DB, u
user := uidToUser[entity.Uid()]
tweets, err := user.GetMeidas(ctx, client, &utils.TimeRange{Min: entity.LatestReleaseTime()})
if v, ok := err.(*twitter.TwitterApiError); ok {
if v.Code == twitter.ErrDependency {
cancel(fmt.Errorf("maybe account is locked"))
continue
} else if v.Code == twitter.ErrExceedPostLimit {
if v.Code == twitter.ErrExceedPostLimit {
cancel(fmt.Errorf("reached the limit for seeing posts today"))
continue
} else if v.Code == twitter.ErrAccountLocked {
cancel(fmt.Errorf("account is locked"))
continue
}
}
if ctx.Err() != nil {
Expand Down
8 changes: 1 addition & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,6 @@ func main() {
}
}()

// retry for failed tweet last run
if err = retryFailedTweets(ctx, dumper, db, client); err != nil {
log.Error("failed to retry previous tweets:", err)
return
}

// dump failed tweets at exit
var todump = make([]*downloading.TweetInEntity, 0)
defer func() {
Expand Down Expand Up @@ -373,7 +367,7 @@ func connectDatabase(path string) (*sqlx.DB, error) {
return nil, err
}

dsn := fmt.Sprintf("file:%s?cache=shared&_journal_mode=WAL&busy_timeout=100000", path)
dsn := fmt.Sprintf("file:%s?_journal_mode=WAL&busy_timeout=120000", path)
db, err := sqlx.Connect("sqlite3", dsn)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion twitter/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Login(ctx context.Context, authToken string, ct0 string) (*resty.Client, st
client.AddRetryCondition(func(r *resty.Response, err error) bool {
// For Twitter API Error
v, ok := err.(*TwitterApiError)
return ok && r.Request.RawRequest.Host == "x.com" && (v.Code == ErrTimeout || v.Code == ErrOverCapacity)
return ok && r.Request.RawRequest.Host == "x.com" && (v.Code == ErrTimeout || v.Code == ErrOverCapacity || v.Code == ErrDependency)
})
client.AddRetryCondition(func(r *resty.Response, err error) bool {
// For Http 429
Expand Down
1 change: 1 addition & 0 deletions twitter/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const (
ErrDependency = 0
ErrExceedPostLimit = 88
ErrOverCapacity = 130
ErrAccountLocked = 326
)

func CheckApiResp(body []byte) error {
Expand Down

0 comments on commit e70881c

Please sign in to comment.