fix: catch NullPointerException in BaseItemDto to FindroidEpisode conversion

This error is caused by the seriesId or seasonId being null. Hide these episodes for now.

Closes #357
Closes #360
This commit is contained in:
Jarne Demeulemeester 2023-05-14 18:39:35 +02:00
parent fd33d52bba
commit 1c117d3c66
No known key found for this signature in database
GPG key ID: 1E5C6AFBD622E9F5
2 changed files with 30 additions and 26 deletions

View file

@ -35,13 +35,14 @@ data class FindroidEpisode(
suspend fun BaseItemDto.toFindroidEpisode( suspend fun BaseItemDto.toFindroidEpisode(
jellyfinRepository: JellyfinRepository, jellyfinRepository: JellyfinRepository,
database: ServerDatabaseDao? = null database: ServerDatabaseDao? = null
): FindroidEpisode { ): FindroidEpisode? {
val sources = mutableListOf<FindroidSource>() val sources = mutableListOf<FindroidSource>()
sources.addAll(mediaSources?.map { it.toFindroidSource(jellyfinRepository, id) } ?: emptyList()) sources.addAll(mediaSources?.map { it.toFindroidSource(jellyfinRepository, id) } ?: emptyList())
if (database != null) { if (database != null) {
sources.addAll(database.getSources(id).map { it.toFindroidSource(database) }) sources.addAll(database.getSources(id).map { it.toFindroidSource(database) })
} }
return FindroidEpisode( return try {
FindroidEpisode(
id = id, id = id,
name = name.orEmpty(), name = name.orEmpty(),
originalTitle = originalTitle, originalTitle = originalTitle,
@ -63,6 +64,9 @@ suspend fun BaseItemDto.toFindroidEpisode(
communityRating = communityRating, communityRating = communityRating,
missing = locationType == LocationType.VIRTUAL, missing = locationType == LocationType.VIRTUAL,
) )
} catch (_: NullPointerException) {
null
}
} }
fun FindroidEpisodeDto.toFindroidEpisode(database: ServerDatabaseDao, userId: UUID): FindroidEpisode { fun FindroidEpisodeDto.toFindroidEpisode(database: ServerDatabaseDao, userId: UUID): FindroidEpisode {

View file

@ -74,7 +74,7 @@ class JellyfinRepositoryImpl(
jellyfinApi.userLibraryApi.getItem( jellyfinApi.userLibraryApi.getItem(
jellyfinApi.userId!!, jellyfinApi.userId!!,
itemId itemId
).content.toFindroidEpisode(this@JellyfinRepositoryImpl, database) ).content.toFindroidEpisode(this@JellyfinRepositoryImpl, database)!!
} }
override suspend fun getMovie(itemId: UUID): FindroidMovie = override suspend fun getMovie(itemId: UUID): FindroidMovie =
@ -254,7 +254,7 @@ class JellyfinRepositoryImpl(
seriesId = seriesId?.toString(), seriesId = seriesId?.toString(),
).content.items ).content.items
.orEmpty() .orEmpty()
.map { it.toFindroidEpisode(this@JellyfinRepositoryImpl) } .mapNotNull { it.toFindroidEpisode(this@JellyfinRepositoryImpl) }
} }
override suspend fun getEpisodes( override suspend fun getEpisodes(
@ -276,7 +276,7 @@ class JellyfinRepositoryImpl(
limit = limit, limit = limit,
).content.items ).content.items
.orEmpty() .orEmpty()
.map { it.toFindroidEpisode(this@JellyfinRepositoryImpl, database) } .mapNotNull { it.toFindroidEpisode(this@JellyfinRepositoryImpl, database) }
} else { } else {
database.getEpisodesBySeasonId(seasonId).map { it.toFindroidEpisode(database, jellyfinApi.userId!!) } database.getEpisodesBySeasonId(seasonId).map { it.toFindroidEpisode(database, jellyfinApi.userId!!) }
} }