From 474699b67d06161e9cd0354496181af0caaee60a Mon Sep 17 00:00:00 2001 From: ta264 Date: Mon, 26 Jul 2021 22:02:30 +0100 Subject: [PATCH] Fixed: Error refreshing author if manually added book edition has been removed from Goodreads Fixes Sentry READARR-Z6 --- .../Goodreads/GoodreadsProxy.cs | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs b/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs index 7a640fad6..6f6eedc20 100644 --- a/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs @@ -137,10 +137,21 @@ namespace NzbDrone.Core.MetadataSource.Goodreads if (existingAuthor != null) { var existingEditions = _editionService.GetEditionsByAuthor(existingAuthor.Id); - var extraEditionIds = existingEditions.Select(x => x.ForeignEditionId).Except(books.Select(x => x.Editions.Value.First().ForeignEditionId)); + var extraEditionIds = existingEditions + .Select(x => x.ForeignEditionId) + .Except(books.Select(x => x.Editions.Value.First().ForeignEditionId)) + .ToList(); _logger.Debug($"Getting data for extra editions {extraEditionIds.ConcatToString()}"); - var extraEditions = extraEditionIds.Select(x => GetBookInfo(x)); + + var extraEditions = new List>>(); + foreach (var id in extraEditionIds) + { + if (TryGetBookInfo(id, true, out var result)) + { + extraEditions.Add(result); + } + } var bookDict = books.ToDictionary(x => x.ForeignBookId); foreach (var edition in extraEditions) @@ -313,6 +324,21 @@ namespace NzbDrone.Core.MetadataSource.Goodreads return null; } + private bool TryGetBookInfo(string foreignEditionId, bool useCache, out Tuple> result) + { + try + { + result = GetBookInfo(foreignEditionId, useCache); + return true; + } + catch (BookNotFoundException e) + { + result = null; + _logger.Warn(e, "Book not found"); + return false; + } + } + public Tuple> GetBookInfo(string foreignEditionId, bool useCache = true) { _logger.Debug("Getting Book with GoodreadsId of {0}", foreignEditionId);