Skip to content

Commit

Permalink
Handle error downloading attachment in archive
Browse files Browse the repository at this point in the history
  • Loading branch information
randomnetcat committed Jan 2, 2024
1 parent 99aebba commit 8020551
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/main/kotlin/org/randomcat/agorabot/util/DefaultArchiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,24 @@ private suspend fun receivePendingDownloads(
val attachmentDir = attachmentsDir.resolve("attachment-$number")
attachmentDir.createDirectory()

val outPath = attachmentDir.resolve(fileName)
try {
val outPath = attachmentDir.resolve(fileName)

logger.info("Downloading channel $channelId attachment $number: $fileName")
logger.info("Downloading channel $channelId attachment $number; name: $fileName; url: ${pendingDownload.attachment.url}")

outPath.outputStream(StandardOpenOption.CREATE_NEW).use { outStream ->
writeAttachmentContentTo(pendingDownload.attachment, outStream)
}
outPath.outputStream(StandardOpenOption.CREATE_NEW).use { outStream ->
writeAttachmentContentTo(pendingDownload.attachment, outStream)
}

logger.info("Finished downloading channel $channelId attachment $number")
logger.info("Finished downloading channel $channelId attachment $number")
} catch (e: Exception) {
logger.error(
"Error downloading channel $channelId attachment $number; name: $fileName; url: ${pendingDownload.attachment.url}",
e,
)

attachmentDir.resolve("ERROR.txt").writeText(e.stackTraceToString())
}
}
}
}
Expand Down

0 comments on commit 8020551

Please sign in to comment.