Best practice for ApiClient with callback 🤔 #20
Nicolaidam
started this conversation in
General
Replies: 1 comment 2 replies
-
After a bit more thinking time... I think creating a publisher in the API Client that is triggered every time a 401 error is received would be a good solution. The outer view model could then subscribe to that publisher |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Thank you very much for providing such an excellent library.
After integrating it into my project, I encountered a small issue that I would appreciate your thoughts on.
I am currently working on an MVVM app that uses normal dependency injection for dependencies such as the API client, MainQueue, etc. For this application, I want to handle all 401 Unauthorized errors in the API client. To achieve this, I have designed it with a callback that that triggers a handleUnauthorized() function. When this callback is triggered, I want to navigate to a login screen, which happens in the handleUnauthorized() function.
I am not entirely satisfied with this solution, but it appeared to be working as intended. However, after migrating to the Dependencies library, I have not been able to come up with a solution on how to handle a callback from the API client. Since it now conforms to the DependencyKey protocol, I no longer have the opportunity to handle the callback by calling a function in the outer view model that I had before. I would greatly appreciate your thoughts on how to handle a problem like this with this Dependencies library.
I look forward to hearing from you.
Beta Was this translation helpful? Give feedback.
All reactions