diff --git a/Sources/EeveeSpotify/Lyrics/Repositories/GeniusLyricsRepository.swift b/Sources/EeveeSpotify/Lyrics/Repositories/GeniusLyricsRepository.swift index bb252d73..d5529fe4 100644 --- a/Sources/EeveeSpotify/Lyrics/Repositories/GeniusLyricsRepository.swift +++ b/Sources/EeveeSpotify/Lyrics/Repositories/GeniusLyricsRepository.swift @@ -53,7 +53,9 @@ struct GeniusLyricsRepository: LyricsRepository { throw error } - let rootResponse = try jsonDecoder.decode(GeniusRootResponse.self, from: data!) + guard let rootResponse = try? jsonDecoder.decode(GeniusRootResponse.self, from: data!) else { + throw LyricsError.DecodingError + } return rootResponse.response } diff --git a/Sources/EeveeSpotify/Lyrics/Repositories/PetitLyricsRepository.swift b/Sources/EeveeSpotify/Lyrics/Repositories/PetitLyricsRepository.swift index 8267c26c..0c1996f6 100644 --- a/Sources/EeveeSpotify/Lyrics/Repositories/PetitLyricsRepository.swift +++ b/Sources/EeveeSpotify/Lyrics/Repositories/PetitLyricsRepository.swift @@ -42,8 +42,12 @@ struct PetitLyricsRepository: LyricsRepository { if let error = error { throw error } + + guard let response = try? XMLDecoder().decode(PetitResponse.self, from: data!) else { + throw LyricsError.DecodingError + } - return try XMLDecoder().decode(PetitResponse.self, from: data!) + return response } // @@ -77,7 +81,7 @@ struct PetitLyricsRepository: LyricsRepository { ) guard let song = response.songs.first else { - throw LyricsError.DecodingError + throw LyricsError.NoSuchSong } return song @@ -99,7 +103,10 @@ struct PetitLyricsRepository: LyricsRepository { switch song.lyricsType { case .wordsSynced: - let lyrics = try XMLDecoder().decode(PetitLyricsData.self, from: lyricsData) + guard let lyrics = try? XMLDecoder().decode(PetitLyricsData.self, from: lyricsData) + else { + throw LyricsError.DecodingError + } return LyricsDto( lines: lyrics.lines.map {