Commit 2f7f5d4
committed
backend: cmd: Refactor CacheMiddleWare by extracting handler
Extract the request handling logic from CacheMiddleWare into a
separate handleCacheRequest function to reduce cognitive complexity
and function length. This removes the need for the nolint directive
and makes the code more maintainable and testable.
Add documentation comment explaining why ErrHandled is checked and
why we return early when it's encountered. This clarifies that
ErrHandled is a sentinel error indicating the request was already
fully processed during cache invalidation, not an actual error.
Change ErrHandled from fmt.Errorf to errors.New to align with Go
best practices for sentinel errors. Sentinel errors should be created
with errors.New rather than fmt.Errorf to enable proper error
comparison with errors.Is.
Add missing return statement after handleError when LoadFromCache
fails to prevent double writing HTTP responses. This ensures the
middleware doesn't continue processing after an error has been
written to the client.1 parent b7546cc commit 2f7f5d4
File tree
3 files changed
+81
-65
lines changed- backend
- cmd
- pkg/k8cache
3 files changed
+81
-65
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1684 | 1684 | | |
1685 | 1685 | | |
1686 | 1686 | | |
1687 | | - | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
1688 | 1690 | | |
1689 | 1691 | | |
1690 | 1692 | | |
| |||
1699 | 1701 | | |
1700 | 1702 | | |
1701 | 1703 | | |
1702 | | - | |
1703 | | - | |
1704 | | - | |
1705 | | - | |
1706 | | - | |
1707 | | - | |
1708 | | - | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
1709 | 1716 | | |
1710 | | - | |
1711 | | - | |
1712 | | - | |
1713 | 1717 | | |
1714 | 1718 | | |
1715 | 1719 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
195 | 191 | | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
200 | 196 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
205 | 210 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 211 | + | |
| 212 | + | |
210 | 213 | | |
211 | | - | |
| 214 | + | |
212 | 215 | | |
213 | | - | |
214 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
215 | 221 | | |
216 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
217 | 225 | | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
223 | 229 | | |
224 | | - | |
225 | | - | |
226 | | - | |
| 230 | + | |
| 231 | + | |
227 | 232 | | |
228 | | - | |
229 | | - | |
230 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
231 | 238 | | |
232 | | - | |
233 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
234 | 243 | | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
| 244 | + | |
239 | 245 | | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
| 246 | + | |
244 | 247 | | |
245 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
246 | 254 | | |
247 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
248 | 262 | | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
| 263 | + | |
| 264 | + | |
254 | 265 | | |
255 | 266 | | |
256 | 267 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | | - | |
| 92 | + | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| |||
0 commit comments