From 41ddba8af46135dd813447181b8515105614bb03 Mon Sep 17 00:00:00 2001 From: Danshil Kokil Mungur Date: Sun, 15 Jan 2023 11:32:38 +0400 Subject: [PATCH] fix(request): mark request as approved if media is already available when retrying failed request (#3244) --- server/entity/MediaRequest.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/server/entity/MediaRequest.ts b/server/entity/MediaRequest.ts index eefbc11f3..fad97ef6b 100644 --- a/server/entity/MediaRequest.ts +++ b/server/entity/MediaRequest.ts @@ -767,7 +767,16 @@ export class MediaRequest { if ( media[this.is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE ) { - throw new Error('Media already available'); + logger.warn('Media already exists, marking request as APPROVED', { + label: 'Media Request', + requestId: this.id, + mediaId: this.media.id, + }); + + const requestRepository = getRepository(MediaRequest); + this.status = MediaRequestStatus.APPROVED; + await requestRepository.save(this); + return; } const radarrMovieOptions: RadarrMovieOptions = { @@ -908,7 +917,16 @@ export class MediaRequest { if ( media[this.is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE ) { - throw new Error('Media already available'); + logger.warn('Media already exists, marking request as APPROVED', { + label: 'Media Request', + requestId: this.id, + mediaId: this.media.id, + }); + + const requestRepository = getRepository(MediaRequest); + this.status = MediaRequestStatus.APPROVED; + await requestRepository.save(this); + return; } const tmdb = new TheMovieDb();