From b9f42edb0c40f86667b1f288d16a48a8788bfda7 Mon Sep 17 00:00:00 2001 From: Sjmarf <78750526+Sjmarf@users.noreply.github.com> Date: Sun, 1 Oct 2023 15:44:41 +0100 Subject: [PATCH] Update --- Mlem/API/Models/APIErrorResponse.swift | 1 + Mlem/Views/Shared/Accounts/Add Account View.swift | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Mlem/API/Models/APIErrorResponse.swift b/Mlem/API/Models/APIErrorResponse.swift index a015e9512..35d8eec4b 100644 --- a/Mlem/API/Models/APIErrorResponse.swift +++ b/Mlem/API/Models/APIErrorResponse.swift @@ -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" } } diff --git a/Mlem/Views/Shared/Accounts/Add Account View.swift b/Mlem/Views/Shared/Accounts/Add Account View.swift index 5a3c07eef..73225c09a 100644 --- a/Mlem/Views/Shared/Accounts/Add Account View.swift +++ b/Mlem/Views/Shared/Accounts/Add Account View.swift @@ -11,6 +11,7 @@ import SwiftUI // swiftlint:disable file_length enum UserIDRetrievalError: Error { case couldNotFetchUserInformation + case instanceIsPrivate } enum Field: Hashable { @@ -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 + } } } @@ -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