fix(user): retry group avatar fetch with IsCommunity on failure#78
Open
diwberg wants to merge 2 commits into
Open
fix(user): retry group avatar fetch with IsCommunity on failure#78diwberg wants to merge 2 commits into
diwberg wants to merge 2 commits into
Conversation
GetProfilePictureInfo rejects group/community JIDs on the regular w:profile:picture query (401 not-authorized), so POST /user/avatar always returned 500 for @g.us numbers. When the first attempt fails for a group JID, retry with IsCommunity: true — the variant whatsmeow documents for community photos. No behavior change for regular user JIDs.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds a retry path for fetching WhatsApp group/community avatars: if the initial GetProfilePictureInfo call fails for a group JID, the service logs the failure and retries once using the IsCommunity flag, keeping behavior unchanged for regular user JIDs. Sequence diagram for GetAvatar group retry with IsCommunitysequenceDiagram
participant ApiClient
participant UserService
participant WhatsmeowClient
participant Logger
ApiClient->>UserService: GetAvatar(data, instance)
UserService->>WhatsmeowClient: GetProfilePictureInfo(ctx, jid, GetProfilePictureParams{Preview})
alt first_call_error_and_group_jid
WhatsmeowClient-->>UserService: error
UserService->>Logger: LogInfo("GetProfilePictureInfo failed for group JID, retrying with IsCommunity")
UserService->>WhatsmeowClient: GetProfilePictureInfo(ctx, jid, GetProfilePictureParams{Preview, IsCommunity})
alt retry_error
WhatsmeowClient-->>UserService: error
UserService->>Logger: LogError("GetProfilePictureInfo failed")
UserService-->>ApiClient: error
else retry_success
WhatsmeowClient-->>UserService: pic
UserService-->>ApiClient: pic
end
else first_call_ok_or_non_group_jid
WhatsmeowClient-->>UserService: pic_or_error
alt error
UserService->>Logger: LogError("GetProfilePictureInfo failed")
UserService-->>ApiClient: error
else success
UserService-->>ApiClient: pic
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The retry path currently triggers for any error on group JIDs; consider restricting the retry to known authorization/not-authorized error types to avoid masking or duplicating unrelated failures.
- You call
u.loggerWrapper.GetLogger(instance.Id)twice in quick succession; consider storing the logger in a local variable to avoid repeated lookups and keep the logging code consistent. - The informational log on the first failure plus the error log on the final failure may produce noisy logs for persistent errors; consider lowering the first message to a more verbose level or only logging on the final outcome.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The retry path currently triggers for any error on group JIDs; consider restricting the retry to known authorization/not-authorized error types to avoid masking or duplicating unrelated failures.
- You call `u.loggerWrapper.GetLogger(instance.Id)` twice in quick succession; consider storing the logger in a local variable to avoid repeated lookups and keep the logging code consistent.
- The informational log on the first failure plus the error log on the final failure may produce noisy logs for persistent errors; consider lowering the first message to a more verbose level or only logging on the final outcome.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…ogging Review feedback: retry only on whatsmeow.ErrProfilePictureUnauthorized (the documented community case) instead of any error, so unrelated failures surface unchanged; hoist the per-instance logger into a local; demote the pre-retry message to debug so persistent failures log a single error.
Author
|
Addressed the review in a112370: the retry is now scoped to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
POST /user/avataralways returns 500 when thenumberis a group JID (…@g.us).GetAvatarcalls whatsmeow'sGetProfilePictureInfowith onlyPreviewset. For group/community JIDs the regularw:profile:picturequery is rejected by WhatsApp with401 not-authorized, which surfaces as a 500 to the API consumer. whatsmeow itself documents this inGetProfilePictureParams: "To get a community photo, you should pass IsCommunity: true, as otherwise you may get a 401 error."Reproduced live:
Fix
When the first
GetProfilePictureInfoattempt fails and the JID server isg.us, retry once withIsCommunity: true. Regular user JIDs are untouched — same single call as before.Testing
go build ./pkg/...clean.url,id,type,direct_path); user JIDs unchanged.Summary by Sourcery
Bug Fixes: