From 5ab2490b08dbc2f724cf0e344f938e0eade084fc Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Mon, 15 Aug 2022 14:49:12 +0200 Subject: [PATCH] Add account error alerts --- Model/Applications/InvidiousAPI.swift | 6 +++++- Model/Applications/PipedAPI.swift | 7 +++++++ Model/NavigationModel.swift | 2 ++ Shared/YatteeApp.swift | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Model/Applications/InvidiousAPI.swift b/Model/Applications/InvidiousAPI.swift index 9a37f9e8..1931d95d 100644 --- a/Model/Applications/InvidiousAPI.swift +++ b/Model/Applications/InvidiousAPI.swift @@ -66,8 +66,12 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { .onSuccess { _ in self.signedIn = true } - .onFailure { _ in + .onFailure { requestError in self.signedIn = false + NavigationModel.shared.presentAlert( + title: "Could not connect with your account", + message: "\(requestError.httpStatusCode ?? -1) - \(requestError.userMessage)\nIf this issue persists, try removing and adding your account again in Settings." + ) } } diff --git a/Model/Applications/PipedAPI.swift b/Model/Applications/PipedAPI.swift index 01162622..2ac47cc2 100644 --- a/Model/Applications/PipedAPI.swift +++ b/Model/Applications/PipedAPI.swift @@ -121,6 +121,13 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { ) .onSuccess { response in self.account.token = response.json.dictionaryValue["token"]?.string ?? "" + if let error = response.json.dictionaryValue["error"]?.string { + NavigationModel.shared.presentAlert( + title: "Could not connect with your account", + message: error + ) + } + self.configure() } } diff --git a/Model/NavigationModel.swift b/Model/NavigationModel.swift index 06770bb3..b2d885bd 100644 --- a/Model/NavigationModel.swift +++ b/Model/NavigationModel.swift @@ -2,6 +2,8 @@ import Foundation import SwiftUI final class NavigationModel: ObservableObject { + static var shared: NavigationModel! + enum TabSelection: Hashable { case favorites case subscriptions diff --git a/Shared/YatteeApp.swift b/Shared/YatteeApp.swift index f53bc298..3284f269 100644 --- a/Shared/YatteeApp.swift +++ b/Shared/YatteeApp.swift @@ -226,6 +226,8 @@ struct YatteeApp: App { navigation.tabSelection = section ?? .search + NavigationModel.shared = navigation + subscriptions.load() playlists.load()