Compare commits

..

2 Commits

Author SHA1 Message Date
Shadowfacts 160f48679b Handle HTTP 206 responses from timelines endpoint 2023-04-18 10:16:38 -04:00
Shadowfacts 4931665b45 Log Sentry installation ID
So when the user taps Get Support and logs are sent we can cross-ref
with recent crashes
2023-04-18 10:10:15 -04:00
4 changed files with 12 additions and 1 deletions

View File

@ -83,7 +83,7 @@ public class Client {
completion(.failure(Error(request: request, type: .invalidResponse)))
return
}
guard response.statusCode == 200 else {
guard response.statusCode == 200 || request.additionalAcceptableHTTPCodes.contains(response.statusCode) else {
let mastodonError = try? Client.decoder.decode(MastodonError.self, from: data)
let type: ErrorType = mastodonError.flatMap { .mastodonError(response.statusCode, $0.description) } ?? .unexpectedStatus(response.statusCode)
completion(.failure(Error(request: request, type: type)))

View File

@ -38,6 +38,8 @@ extension Timeline {
request.queryParameters.append("local" => true)
}
request.range = range
// 206 can happen when the timeline is being regenerated and therefore is incomplete
request.additionalAcceptableHTTPCodes = [206]
return request
}
}

View File

@ -13,6 +13,7 @@ public struct Request<ResultType: Decodable>: Sendable {
let endpoint: Endpoint
let body: Body
var queryParameters: [Parameter]
var additionalAcceptableHTTPCodes: [Int] = []
init(method: Method, path: Endpoint, body: Body = EmptyBody(), queryParameters: [Parameter] = []) {
self.method = method

View File

@ -14,6 +14,7 @@ import UserAccounts
import ComposeUI
let stateRestorationLogger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "StateRestoration")
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "AppDelegate")
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
@ -94,6 +95,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return Preferences.shared.reportErrorsAutomatically ? event : nil
}
}
if let clazz = NSClassFromString("SentryInstallation"),
let objClazz = clazz as AnyObject as? NSObjectProtocol,
objClazz.responds(to: Selector(("id"))),
let id = objClazz.perform(Selector(("id"))).takeRetainedValue() as? String {
logger.info("Initialized Sentry with installation/user ID: \(id)")
}
}
override func buildMenu(with builder: UIMenuBuilder) {