fix: Prevent transaction rollback when cover download fails (#1971)

Cover download failures in updateThumbnailIfNeeded() were propagating
exceptions that poisoned the @Transactional method, causing the entire
book's metadata update to roll back - even though the metadata itself
was fetched successfully.

This commonly occurs when CDNs serve WebP images with JPEG extensions/
headers (e.g., Amazon CDN), causing ImageIO to fail validation.

The fix wraps the thumbnail download in a try-catch and logs a warning
instead of propagating the exception. Cover failures are non-critical
and shouldn't prevent metadata updates from persisting.
This commit is contained in:
cwar
2025-12-25 11:17:28 -07:00
committed by GitHub
parent 21bcc7d382
commit cb91a4ae6e
@@ -356,7 +356,12 @@ public class BookMetadataUpdater {
}
if (!set) return;
if (!StringUtils.hasText(m.getThumbnailUrl()) || isLocalOrPrivateUrl(m.getThumbnailUrl())) return;
fileService.createThumbnailFromUrl(bookId, m.getThumbnailUrl());
try {
fileService.createThumbnailFromUrl(bookId, m.getThumbnailUrl());
} catch (Exception ex) {
log.warn("Failed to download cover for book {}: {}", bookId, ex.getMessage());
// Don't rethrow - cover failures shouldn't roll back metadata updates
}
}
private void updateLocks(BookMetadata m, BookMetadataEntity e) {