From 2dcf7beb23857cc102da44e7a6c6dbb3f3cc72b9 Mon Sep 17 00:00:00 2001 From: Bosco Ho Date: Tue, 10 Oct 2023 23:55:44 -0700 Subject: [PATCH] Show error when instance is private (#683) Commit: 6d1a997952869b1efd936b51b8ccc1fb7c62044d [6d1a9979] --- 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..2391c0dde 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 a private instance." case APIClientError.encoding: // TODO: we should add better validation // at the UI layer as encoding failures can be caught