fix: 🐛 fix error wrapping
continuous-integration/drone/push Build is passing Details

main
RaviAnand Mohabir 1 year ago
parent 17051afc57
commit dd5820fe44

@ -23,12 +23,12 @@ func GetUsers(ctx context.Context, app *core.App) ([]*models.User, error) {
cursor, err := coll.Find(context.TODO(), filter, opts) cursor, err := coll.Find(context.TODO(), filter, opts)
if err != nil { if err != nil {
return nil, fmt.Errorf("couldn't fetch users %v", err) return nil, fmt.Errorf("couldn't fetch users %w", err)
} }
var results []*models.User var results []*models.User
if err = cursor.All(ctx, &results); err != nil { if err = cursor.All(ctx, &results); err != nil {
return nil, fmt.Errorf("couldn't fetch users %v", err) return nil, fmt.Errorf("couldn't fetch users %w", err)
} }
return results, nil return results, nil
@ -43,7 +43,7 @@ func GetUser(ctx context.Context, app *core.App, spotifyID string) (*models.User
var result models.User var result models.User
err := coll.FindOne(context.TODO(), filter, opts).Decode(&result) err := coll.FindOne(context.TODO(), filter, opts).Decode(&result)
if err != nil { if err != nil {
return nil, fmt.Errorf("couldn't fetch user %v", err) return nil, fmt.Errorf("couldn't fetch user %w", err)
} }
return &result, nil return &result, nil
@ -62,7 +62,7 @@ func GetSpotifyClient(ctx context.Context, app *core.App, user *models.User) (*s
_, err := coll.UpdateByID(ctx, user.ID, bson.D{{"$set", bson.D{{"token", *newToken}}}}) _, err := coll.UpdateByID(ctx, user.ID, bson.D{{"$set", bson.D{{"token", *newToken}}}})
if err != nil { if err != nil {
return nil, fmt.Errorf("couldn't update token %v", err) return nil, fmt.Errorf("couldn't update token %w", err)
} }
user.Token = *newToken user.Token = *newToken
@ -79,7 +79,7 @@ func SaveUserToken(ctx context.Context, app *core.App, spotifyID string, token *
result, err := GetUser(ctx, app, spotifyID) result, err := GetUser(ctx, app, spotifyID)
if err != nil && !errors.Is(err, mongo.ErrNoDocuments) { if err != nil && !errors.Is(err, mongo.ErrNoDocuments) {
return nil, fmt.Errorf("couldn't fetch user %v", err) return nil, fmt.Errorf("couldn't fetch user %w", err)
} }
if err == mongo.ErrNoDocuments { if err == mongo.ErrNoDocuments {
@ -87,13 +87,13 @@ func SaveUserToken(ctx context.Context, app *core.App, spotifyID string, token *
_, err = coll.InsertOne(context.TODO(), doc) _, err = coll.InsertOne(context.TODO(), doc)
if err != nil { if err != nil {
return nil, fmt.Errorf("couldn't write user %v", err) return nil, fmt.Errorf("couldn't write user %w", err)
} }
} else { } else {
_, err := coll.UpdateByID(ctx, result.ID, bson.D{{"$set", bson.D{{"token", *token}}}}) _, err := coll.UpdateByID(ctx, result.ID, bson.D{{"$set", bson.D{{"token", *token}}}})
if err != nil { if err != nil {
return nil, fmt.Errorf("couldn't write user %v", err) return nil, fmt.Errorf("couldn't write user %w", err)
} }
result.Token = *token result.Token = *token

Loading…
Cancel
Save