More detailed error when status URL decoding fails

See #373
This commit is contained in:
Shadowfacts 2023-04-23 14:38:00 -04:00
parent 6c5909c800
commit 4401503b85
1 changed files with 6 additions and 1 deletions

View File

@ -48,7 +48,12 @@ public final class Status: StatusProtocol, Decodable, Sendable {
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(String.self, forKey: .id) self.id = try container.decode(String.self, forKey: .id)
self.uri = try container.decode(String.self, forKey: .uri) self.uri = try container.decode(String.self, forKey: .uri)
do {
self.url = try container.decodeIfPresent(WebURL.self, forKey: .url) self.url = try container.decodeIfPresent(WebURL.self, forKey: .url)
} catch {
let s = (try? container.decode(String.self, forKey: .url)) ?? "<failed to decode string>"
throw DecodingError.dataCorruptedError(forKey: .url, in: container, debugDescription: "Could not decode URL '\(s)', reason: \(String(describing: error))")
}
self.account = try container.decode(Account.self, forKey: .account) self.account = try container.decode(Account.self, forKey: .account)
self.inReplyToID = try container.decodeIfPresent(String.self, forKey: .inReplyToID) self.inReplyToID = try container.decodeIfPresent(String.self, forKey: .inReplyToID)
self.inReplyToAccountID = try container.decodeIfPresent(String.self, forKey: .inReplyToAccountID) self.inReplyToAccountID = try container.decodeIfPresent(String.self, forKey: .inReplyToAccountID)