Commit a7ed7b5204
Unsigned
Layout: unified · split
Hutch/Views/Inbox/ThreadViewModel.swift +5 −29
| @@ -684,36 +684,12 @@ final class ThreadViewModel { | |||
| 684 | query: String, | 684 | query: String, |
| 685 | variables: [String: any Sendable] | 685 | variables: [String: any Sendable] |
| 686 | ) async throws -> T { | 686 | ) async throws -> T { |
| 687 | guard let token = KeychainHelper.loadToken(), !token.isEmpty else { | 687 | try await client.execute( |
| 688 | throw SRHTError.unauthorized | 688 | service: .lists, |
| 689 | } | 689 | query: query, |
| 690 | 690 | variables: variables, | |
| 691 | var request = URLRequest(url: SRHTService.lists.url) | 691 | responseType: T.self |
| 692 | request.httpMethod = "POST" | ||
| 693 | request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") | ||
| 694 | request.setValue("application/json", forHTTPHeaderField: "Content-Type") | ||
| 695 | |||
| 696 | let encoder = JSONEncoder() | ||
| 697 | request.httpBody = try encoder.encode( | ||
| 698 | GraphQLRequestBody( | ||
| 699 | query: query, | ||
| 700 | variables: variables.mapValues { AnyCodable($0) } | ||
| 701 | ) | ||
| 702 | ) | 692 | ) |
| 703 | |||
| 704 | let (data, _) = try await URLSession.shared.data(for: request) | ||
| 705 | let decoder = JSONDecoder() | ||
| 706 | decoder.dateDecodingStrategy = .srhtFlexible | ||
| 707 | let envelope = try decoder.decode(GraphQLResponse<T>.self, from: data) | ||
| 708 | if let errors = envelope.errors, !errors.isEmpty { | ||
| 709 | throw SRHTError.graphQLErrors(errors) | ||
| 710 | } | ||
| 711 | guard let payload = envelope.data else { | ||
| 712 | throw SRHTError.decodingError( | ||
| 713 | DecodingError.dataCorrupted(.init(codingPath: [], debugDescription: "No data in thread detail response")) | ||
| 714 | ) | ||
| 715 | } | ||
| 716 | return payload | ||
| 717 | } | 693 | } |
| 718 | 694 | ||
| 719 | private static func isRecoverableNoRows(_ error: Error) -> Bool { | 695 | private static func isRecoverableNoRows(_ error: Error) -> Bool { |