Skip to content

Commit

Permalink
Ignore Steam import friends unauthorized errors (heroiclabs#1206)
Browse files Browse the repository at this point in the history
Do not log Steam friend import API unauthorized errors.
The error indicates that the Steam account is private or friends are only shared with other friends.
  • Loading branch information
sesposito authored Apr 24, 2024
1 parent 00cc648 commit e3f170c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion server/core_authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,9 @@ func importSteamFriends(ctx context.Context, logger *zap.Logger, db *sql.DB, tra
logger = logger.With(zap.String("userID", userID.String()))

steamProfiles, err := client.GetSteamFriends(ctx, publisherKey, steamId)
if err != nil {
var unauthorizedErr *social.UnauthorizedError
if err != nil && !errors.As(err, &unauthorizedErr) {
// If error is unauthorized it means the profile or friends is private, ignore.
logger.Error("Could not import Steam friends.", zap.Error(err))
return status.Error(codes.Unauthenticated, "Could not authenticate Steam profile.")
}
Expand Down
12 changes: 10 additions & 2 deletions social/social.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,17 @@ func (c *Client) requestRaw(ctx context.Context, provider, path string, headers
case 200:
return body, nil
case 401:
return nil, fmt.Errorf("%v error url %v, status code %v, body %s", provider, path, resp.StatusCode, body)
return nil, &UnauthorizedError{Err: fmt.Errorf("%v url: %q, status code: %q, body: %q", provider, path, resp.StatusCode, body)}
default:
c.logger.Warn("error response code from social request", zap.String("provider", provider), zap.Int("code", resp.StatusCode), zap.String("body", string(body)))
return nil, fmt.Errorf("%v error url %v, status code %v, body %s", provider, path, resp.StatusCode, body)
return nil, fmt.Errorf("%v url: %q, status code: %q, body: %q", provider, path, resp.StatusCode, body)
}
}

type UnauthorizedError struct {
Err error
}

func (e *UnauthorizedError) Error() string { return e.Err.Error() }

func (e *UnauthorizedError) Unwrap() error { return e.Err }

0 comments on commit e3f170c

Please sign in to comment.