Skip to content

Commit

Permalink
fix: store message with metadata in the error logs when saving a ment…
Browse files Browse the repository at this point in the history
…ion fails
  • Loading branch information
ewan-escience committed May 15, 2024
1 parent d6200a9 commit d7762e1
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ public void save(Collection<MentionRecord> mentions) {

LOGGER.warn("Failed to save mention: {} / {} / {}", mention.doi, mention.externalId, mention.source, e);

String metadataMessage = "Failed to save mention: DOI %s, external ID %s, source %s".formatted(mention.doi, mention.externalId, mention.source);
RuntimeException exceptionWithMetadata = new RuntimeException(metadataMessage, e);
if (mention.doi == null) {
Utils.saveExceptionInDatabase("Mention scraper", "mention", null, e);
Utils.saveExceptionInDatabase("Mention scraper", "mention", null, exceptionWithMetadata);
} else {
// We will try to update the scraped_at field, so that it goes back into the queue for being scraped
// Note that this operation in itself may also fail.
Expand All @@ -118,9 +120,9 @@ public void save(Collection<MentionRecord> mentions) {
ZonedDateTime.now(),
"scraped_at");

Utils.saveExceptionInDatabase("Mention scraper", "mention", UUID.fromString(id), e);
Utils.saveExceptionInDatabase("Mention scraper", "mention", UUID.fromString(id), exceptionWithMetadata);
} else {
Utils.saveExceptionInDatabase("Mention scraper", "mention", null, e);
Utils.saveExceptionInDatabase("Mention scraper", "mention", null, exceptionWithMetadata);
}
} catch (Exception e2) {
LOGGER.warn("Failed to save exception in database", e2);
Expand Down

0 comments on commit d7762e1

Please sign in to comment.