You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello everyone. I am trying to adapt a Network Client to the TCA architecture and can't find serious examples. In my MVVM project, I have a Network Client that handles creating requests, processing errors, refreshing tokens, and depending on the error, it can either navigate the user to the login screen or just display errors in pop-up windows. I understand how to create simple effects, but is it possible to implement this globally? For example:
static func handleError(_ error: NetworkClientError) -> Effect<UserAction, Never> {
switch error {
case .unauthorized, .tokenRefreshFailed, .logoutImmediately:
// Trigger global navigation to LoginView
return Effect(value: .navigateToLogin)
default:
// Show an alert with the error message
return Effect(value: .showAlert(errorMessage(for: error)))
}
}
public func send<T: Decodable>(_ type: T.Type, request: Request) async throws -> T {
do {
return try await performRequest(request)
}
catch NetworkClientError.retryWithNewToken {
let newToken = try await performRefreshRequest()
guard let providerToken = newToken as? Provider.Token else {
throw NetworkClientError.unauthorized
}
try await tokenProvider.setToken(providerToken)
return try await performRequest(request)
}
catch NetworkClientError.showAlert(let message) {
throw NetworkClientError.showAlert(message: message)
// IN REAL APP here notification for SwiftUI but how make it in TCA?
}
catch
NetworkClientError.unauthorized,
NetworkClientError.tokenRefreshFailed,
NetworkClientError.logoutImmediately {
try await logout()
throw NetworkClientError.unauthorized
// IN REAL APP here notification for user manager and change View
} catch {
throw error
}
}
The main problem is that I didn’t need to handle every request and response, the manager took care of that. Now I only understand how to handle each request very locally.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello everyone. I am trying to adapt a Network Client to the TCA architecture and can't find serious examples. In my MVVM project, I have a Network Client that handles creating requests, processing errors, refreshing tokens, and depending on the error, it can either navigate the user to the login screen or just display errors in pop-up windows. I understand how to create simple effects, but is it possible to implement this globally? For example:
The main problem is that I didn’t need to handle every request and response, the manager took care of that. Now I only understand how to handle each request very locally.
Beta Was this translation helpful? Give feedback.
All reactions