Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf committed Oct 1, 2023
1 parent c4c42c5 commit b9f42ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions Mlem/API/Models/APIErrorResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ extension APIErrorResponse {
var isNotLoggedIn: Bool { error == "not_logged_in" }
var userRegistrationPending: Bool { registrationErrors.contains(error) }
var emailNotVerified: Bool { registrationErrors.contains(error) }
var instanceIsPrivate: Bool { error == "instance_is_private" }
}
10 changes: 9 additions & 1 deletion Mlem/Views/Shared/Accounts/Add Account View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftUI
// swiftlint:disable file_length
enum UserIDRetrievalError: Error {
case couldNotFetchUserInformation
case instanceIsPrivate
}

enum Field: Hashable {
Expand Down Expand Up @@ -353,7 +354,12 @@ struct AddSavedInstanceView: View {
.person
} catch {
print("getUserId Error info: \(error)")
throw UserIDRetrievalError.couldNotFetchUserInformation
switch error {
case let APIClientError.response(errorResponse, _) where errorResponse.instanceIsPrivate:
throw UserIDRetrievalError.instanceIsPrivate
default:
throw UserIDRetrievalError.couldNotFetchUserInformation
}
}
}

Expand All @@ -364,6 +370,8 @@ struct AddSavedInstanceView: View {
message = "Could not connect to \(instance)"
case UserIDRetrievalError.couldNotFetchUserInformation:
message = "Mlem couldn't fetch you account's information.\nFile a bug report."
case UserIDRetrievalError.instanceIsPrivate:
message = "Instance is private."
case APIClientError.encoding:
// TODO: we should add better validation
// at the UI layer as encoding failures can be caught
Expand Down

0 comments on commit b9f42ed

Please sign in to comment.