Skip to content

Commit c23117e

Browse files
authored
feat(requests): mark requests as failed when Radarr/Sonarr unreachable (#2171)
Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me>
1 parent 61e0377 commit c23117e

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

server/subscriber/MediaRequestSubscriber.ts

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,32 @@ export class MediaRequestSubscriber implements EntitySubscriberInterface<MediaRe
446446
mediaId: entity.media.id,
447447
});
448448
} catch (e) {
449-
logger.error('Something went wrong sending request to Radarr', {
450-
label: 'Media Request',
451-
errorMessage: e.message,
452-
requestId: entity.id,
453-
mediaId: entity.media.id,
449+
const requestRepository = getRepository(MediaRequest);
450+
const mediaRepository = getRepository(Media);
451+
const media = await mediaRepository.findOne({
452+
where: { id: entity.media.id },
454453
});
455-
throw new Error(e.message);
454+
455+
if (media) {
456+
entity.status = MediaRequestStatus.FAILED;
457+
await requestRepository.save(entity);
458+
459+
logger.warn(
460+
'Failed to send movie request to Radarr due to connection or configuration error, marking status as FAILED',
461+
{
462+
label: 'Media Request',
463+
requestId: entity.id,
464+
mediaId: entity.media.id,
465+
errorMessage: e.message,
466+
}
467+
);
468+
469+
MediaRequest.sendNotification(
470+
entity,
471+
media,
472+
Notification.MEDIA_FAILED
473+
);
474+
}
456475
}
457476
}
458477
}
@@ -769,13 +788,32 @@ export class MediaRequestSubscriber implements EntitySubscriberInterface<MediaRe
769788
mediaId: entity.media.id,
770789
});
771790
} catch (e) {
772-
logger.error('Something went wrong sending request to Sonarr', {
773-
label: 'Media Request',
774-
errorMessage: e.message,
775-
requestId: entity.id,
776-
mediaId: entity.media.id,
791+
const requestRepository = getRepository(MediaRequest);
792+
const mediaRepository = getRepository(Media);
793+
const media = await mediaRepository.findOne({
794+
where: { id: entity.media.id },
777795
});
778-
throw new Error(e.message);
796+
797+
if (media) {
798+
entity.status = MediaRequestStatus.FAILED;
799+
await requestRepository.save(entity);
800+
801+
logger.warn(
802+
'Failed to send series request to Sonarr due to connection or configuration error, marking status as FAILED',
803+
{
804+
label: 'Media Request',
805+
requestId: entity.id,
806+
mediaId: entity.media.id,
807+
errorMessage: e.message,
808+
}
809+
);
810+
811+
MediaRequest.sendNotification(
812+
entity,
813+
media,
814+
Notification.MEDIA_FAILED
815+
);
816+
}
779817
}
780818
}
781819
}

0 commit comments

Comments
 (0)