Initialize the author as nil if it is unparsable. Fixes #3034

This commit is contained in:
Maurice Parker 2021-05-06 13:52:50 -05:00
parent a03430a790
commit d631d4d382

View File

@ -10,7 +10,7 @@ import Foundation
import RSParser import RSParser
import RSCore import RSCore
final class FeedbinEntry: Codable { final class FeedbinEntry: Decodable {
let articleID: Int let articleID: Int
let feedID: Int let feedID: Int
@ -50,14 +50,25 @@ final class FeedbinEntry: Codable {
} }
} }
struct FeedbinEntryJSONFeed: Codable { struct FeedbinEntryJSONFeed: Decodable {
let jsonFeedAuthor: FeedbinEntryJSONFeedAuthor? let jsonFeedAuthor: FeedbinEntryJSONFeedAuthor?
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case jsonFeedAuthor = "author" case jsonFeedAuthor = "author"
} }
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
do {
jsonFeedAuthor = try container.decode(FeedbinEntryJSONFeedAuthor.self, forKey: .jsonFeedAuthor)
} catch {
jsonFeedAuthor = nil
}
}
} }
struct FeedbinEntryJSONFeedAuthor: Codable { struct FeedbinEntryJSONFeedAuthor: Decodable {
let url: String? let url: String?
let avatarURL: String? let avatarURL: String?
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {