From cd25344f741e8c97b113b36eb6babc7be490114d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 30 Jun 2022 09:25:17 +0200 Subject: [PATCH] Reduce lazy static error logs --- server/lib/files-cache/videos-caption-cache.ts | 11 +++++++++-- server/lib/files-cache/videos-preview-cache.ts | 14 ++++++++++---- server/lib/files-cache/videos-torrent-cache.ts | 15 +++++++++++---- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/server/lib/files-cache/videos-caption-cache.ts b/server/lib/files-cache/videos-caption-cache.ts index 2927c37eb..d21acf4ef 100644 --- a/server/lib/files-cache/videos-caption-cache.ts +++ b/server/lib/files-cache/videos-caption-cache.ts @@ -1,4 +1,5 @@ import { join } from 'path' +import { logger } from '@server/helpers/logger' import { doRequestAndSaveToFile } from '@server/helpers/requests' import { CONFIG } from '../../initializers/config' import { FILES_CACHE } from '../../initializers/constants' @@ -41,9 +42,15 @@ class VideosCaptionCache extends AbstractVideoStaticFileCache { const remoteUrl = videoCaption.getFileUrl(video) const destPath = join(FILES_CACHE.VIDEO_CAPTIONS.DIRECTORY, videoCaption.filename) - await doRequestAndSaveToFile(remoteUrl, destPath) + try { + await doRequestAndSaveToFile(remoteUrl, destPath) - return { isOwned: false, path: destPath } + return { isOwned: false, path: destPath } + } catch (err) { + logger.info('Cannot fetch remote caption file %s.', remoteUrl, { err }) + + return undefined + } } } diff --git a/server/lib/files-cache/videos-preview-cache.ts b/server/lib/files-cache/videos-preview-cache.ts index b7a8d6105..48d2cb52c 100644 --- a/server/lib/files-cache/videos-preview-cache.ts +++ b/server/lib/files-cache/videos-preview-cache.ts @@ -37,13 +37,19 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache { const preview = video.getPreview() const destPath = join(FILES_CACHE.PREVIEWS.DIRECTORY, preview.filename) - const remoteUrl = preview.getFileUrl(video) - await doRequestAndSaveToFile(remoteUrl, destPath) - logger.debug('Fetched remote preview %s to %s.', remoteUrl, destPath) + try { + await doRequestAndSaveToFile(remoteUrl, destPath) - return { isOwned: false, path: destPath } + logger.debug('Fetched remote preview %s to %s.', remoteUrl, destPath) + + return { isOwned: false, path: destPath } + } catch (err) { + logger.info('Cannot fetch remote preview file %s.', remoteUrl, { err }) + + return undefined + } } } diff --git a/server/lib/files-cache/videos-torrent-cache.ts b/server/lib/files-cache/videos-torrent-cache.ts index c8188b79f..a6bf98dd4 100644 --- a/server/lib/files-cache/videos-torrent-cache.ts +++ b/server/lib/files-cache/videos-torrent-cache.ts @@ -1,11 +1,12 @@ import { join } from 'path' +import { logger } from '@server/helpers/logger' import { doRequestAndSaveToFile } from '@server/helpers/requests' import { VideoFileModel } from '@server/models/video/video-file' +import { MVideo, MVideoFile } from '@server/types/models' import { CONFIG } from '../../initializers/config' import { FILES_CACHE } from '../../initializers/constants' import { VideoModel } from '../../models/video/video' import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' -import { MVideo, MVideoFile } from '@server/types/models' class VideosTorrentCache extends AbstractVideoStaticFileCache { @@ -46,11 +47,17 @@ class VideosTorrentCache extends AbstractVideoStaticFileCache { const remoteUrl = file.getRemoteTorrentUrl(video) const destPath = join(FILES_CACHE.TORRENTS.DIRECTORY, file.torrentFilename) - await doRequestAndSaveToFile(remoteUrl, destPath) + try { + await doRequestAndSaveToFile(remoteUrl, destPath) - const downloadName = this.buildDownloadName(video, file) + const downloadName = this.buildDownloadName(video, file) - return { isOwned: false, path: destPath, downloadName } + return { isOwned: false, path: destPath, downloadName } + } catch (err) { + logger.info('Cannot fetch remote torrent file %s.', remoteUrl, { err }) + + return undefined + } } private buildDownloadName (video: MVideo, file: MVideoFile) {