Add more logging to onboarding VC

This commit is contained in:
Shadowfacts 2024-04-17 17:04:32 -04:00
parent c6b230414e
commit 043a708515
1 changed files with 15 additions and 1 deletions

View File

@ -116,10 +116,13 @@ class OnboardingViewController: UINavigationController {
}
private func tryLogin(to instanceURL: URL, updateStatus: (String) -> Void) async throws {
logger.debug("Attempting to log in to \(instanceURL, privacy: .public)")
let mastodonController = MastodonController(instanceURL: instanceURL, transient: true)
let clientID: String
let clientSecret: String
if let clientInfo, clientInfo.url == instanceURL {
logger.debug("Using client info from previous attempt")
clientID = clientInfo.id
clientSecret = clientInfo.secret
} else {
@ -127,21 +130,32 @@ class OnboardingViewController: UINavigationController {
do {
(clientID, clientSecret) = try await mastodonController.registerApp()
self.clientInfo = (instanceURL, clientID, clientSecret)
logger.debug("Obtained client info")
updateStatus("Reticulating Splines")
try await Task.sleep(nanoseconds: 500 * NSEC_PER_MSEC)
} catch {
logger.error("Failed to register app: \(String(describing: error), privacy: .public)")
throw Error.registeringApp(error)
}
}
updateStatus("Logging in")
let authCode = try await getAuthorizationCode(instanceURL: instanceURL, clientID: clientID)
let authCode: String
do {
authCode = try await getAuthorizationCode(instanceURL: instanceURL, clientID: clientID)
logger.debug("Obtained authorization code")
} catch {
logger.error("Failed to get auth code: \(String(describing: error), privacy: .public)")
throw error
}
updateStatus("Authorizing")
let accessToken: String
do {
accessToken = try await retrying("Getting access token") {
try await mastodonController.authorize(authorizationCode: authCode)
}
logger.debug("Obtained access token")
} catch {
logger.error("Failed to get access token: \(String(describing: error), privacy: .public)")
throw Error.gettingAccessToken(error)
}