Skip to content

Commit

Permalink
fix: improve error handling in Wikipedia image provider
Browse files Browse the repository at this point in the history
- Enhanced the queryAuthorInfo function to handle missing license name and URL gracefully.
- Added debug logging to provide insights when license information is not found, defaulting to 'Unknown' for license name and an empty string for license URL.
- This change improves the robustness of the image provider by preventing failures due to missing metadata.
  • Loading branch information
tphakala committed Dec 21, 2024
1 parent 17f5cc8 commit 50472bf
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/imageprovider/wikipedia.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,18 @@ func (l *wikiMediaProvider) queryAuthorInfo(reqID, thumbnailURL string) (*wikiMe

licenseName, err := extMetadata.GetString("LicenseShortName", "value")
if err != nil {
return nil, fmt.Errorf("failed to get license name from extmetadata: %w", err)
if l.debug {
log.Printf("[%s] Debug: License name not found, using 'Unknown'", reqID)
}
licenseName = "Unknown"
}

licenseURL, err := extMetadata.GetString("LicenseUrl", "value")
if err != nil {
return nil, fmt.Errorf("failed to get license URL from extmetadata: %w", err)
if l.debug {
log.Printf("[%s] Debug: License URL not found, using empty string", reqID)
}
licenseURL = ""
}

artistHref, err := extMetadata.GetString("Artist", "value")
Expand Down

0 comments on commit 50472bf

Please sign in to comment.