Commit 9972274
committed
refactor(core)!: Centralize rate limit handling with events
This commit refactors the application's rate limit handling to be more robust and centralized. Previously, rate limit checks were scattered, leading to inconsistent behavior. The new approach introduces a `SharedFlow` event system within the `RateLimitRepository`.
When the GitHub API rate limit is exceeded, a `RateLimitException` is now thrown immediately from the `HttpClient`'s response handler. This exception is caught in repository implementations and re-thrown, ensuring that network operations are halted promptly. The exception propagates up to ViewModels, which now catch it to prevent crashes and stop loading indicators.
A global `rateLimitExhaustedEvent` is emitted from the `RateLimitRepository`, which the `MainViewModel` observes to display a single, consistent rate limit dialog to the user. This avoids showing multiple dialogs or leaving the UI in an inconsistent loading state.
- **refactor(core)!**: Modified `HttpClient` to throw a `RateLimitException` immediately upon detection, rather than returning a `Result.failure`. This is a breaking change for repository implementations.
- **refactor(core)!**: Introduced `rateLimitExhaustedEvent` as a `SharedFlow` in `RateLimitRepository` to signal when the API limit has been hit.
- **feat(app)**: The `MainViewModel` now listens to `rateLimitExhaustedEvent` to globally manage and display the rate limit dialog.
- **refactor(details, dev-profile)**: Updated ViewModels and repositories to catch and handle the `RateLimitException`, preventing crashes and ensuring UI loading states are correctly reset.
- **fix(details)**: Resolved an issue where the details screen would show a generic error on rate limit instead of gracefully stopping. Data fetched before the limit is now displayed.
- **fix(home)**: Prevented a crash when rapidly switching categories by ensuring the previous category-switching job is cancelled before starting a new one.
- **chore(files)**: Performed minor project cleanup, including renaming `App.kt` to `Main.kt` and relocating `RateLimitDialog.kt`.
- **chore(domain)**: Removed the unused `trendingScore` property from the `GithubRepoSummary` model.1 parent 3969bcb commit 9972274
13 files changed
Lines changed: 132 additions & 78 deletions
File tree
- composeApp/src/commonMain/kotlin/zed/rainxch/githubstore
- app
- components
- state
- core
- data/src/commonMain/kotlin/zed/rainxch/core/data
- network
- repository
- domain/src/commonMain/kotlin/zed/rainxch/core/domain
- model
- repository
- feature
- details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation
- dev-profile
- data/src/commonMain/kotlin/zed/rainxch/devprofile/data/repository
- presentation/src/commonMain/kotlin/zed/rainxch/devprofile/presentation
- home/presentation/src/commonMain/kotlin/zed/rainxch/home/presentation
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
| 81 | + | |
85 | 82 | | |
86 | 83 | | |
87 | 84 | | |
88 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
98 | 101 | | |
99 | 102 | | |
100 | 103 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
17 | 25 | | |
18 | 26 | | |
19 | 27 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | 20 | | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
Lines changed: 39 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
| 81 | + | |
| 82 | + | |
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
| |||
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
94 | 101 | | |
95 | 102 | | |
96 | 103 | | |
| |||
100 | 107 | | |
101 | 108 | | |
102 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
103 | 113 | | |
104 | 114 | | |
105 | 115 | | |
| |||
112 | 122 | | |
113 | 123 | | |
114 | 124 | | |
115 | | - | |
116 | | - | |
| 125 | + | |
| 126 | + | |
117 | 127 | | |
118 | 128 | | |
119 | 129 | | |
120 | 130 | | |
121 | 131 | | |
122 | | - | |
123 | | - | |
124 | | - | |
| 132 | + | |
125 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
126 | 137 | | |
127 | 138 | | |
128 | 139 | | |
| |||
132 | 143 | | |
133 | 144 | | |
134 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
135 | 149 | | |
136 | 150 | | |
137 | 151 | | |
| |||
144 | 158 | | |
145 | 159 | | |
146 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
147 | 164 | | |
148 | 165 | | |
149 | 166 | | |
| |||
152 | 169 | | |
153 | 170 | | |
154 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
155 | 175 | | |
156 | 176 | | |
157 | 177 | | |
| |||
177 | 197 | | |
178 | 198 | | |
179 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
180 | 203 | | |
181 | 204 | | |
182 | 205 | | |
| |||
192 | 215 | | |
193 | 216 | | |
194 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
195 | 223 | | |
196 | 224 | | |
197 | 225 | | |
| |||
221 | 249 | | |
222 | 250 | | |
223 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
224 | 258 | | |
225 | 259 | | |
226 | 260 | | |
| |||
0 commit comments