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
refactor: update caching strategy and response handling documentation
- Clarified usage of `whenConstOrNull` and `toRegisteredStatusCode()`
- Improved regex pattern for status code matching with negative lookarounds
- Enhanced test cases for regex pattern validation
Copy file name to clipboardExpand all lines: extension/mcp/prompts/cache_strategy.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,10 +27,10 @@ Follow these steps:
27
27
-`501 Not Implemented` — long TTL, unlikely to change soon
28
28
-`204`, `203`, `206`, `300`, `414` — short to moderate TTL depending on use case
29
29
30
-
Use `whenConstOrNull` to express this as a compile-time mapping:
30
+
Use `whenConstOrNull` to express this as a compile-time mapping (`whenConstOrNull` is on `StatusCode`, so convert from raw `int` first):
31
31
32
32
```dart
33
-
final ttl = statusCode.whenConstOrNull(
33
+
final ttl = rawStatusCode.toRegisteredStatusCode()?.whenConstOrNull(
34
34
okHttp200: Duration(minutes: 5),
35
35
noContentHttp204: Duration(minutes: 1),
36
36
notFoundHttp404: Duration(minutes: 10),
@@ -47,5 +47,5 @@ Follow these steps:
47
47
4.**Emit a complete, reusable function** that:
48
48
- Checks `isStatusCode` before doing anything (guards against invalid codes)
49
49
- Uses `isCacheable` to gate the write
50
-
- Uses `whenConstOrNull` or `whenConst` for TTL assignment (no runtime allocations)
50
+
- Uses `toRegisteredStatusCode()?.whenConstOrNull(...)` for TTL assignment — convert first since these methods are on `StatusCode`, not raw `int` (no runtime allocations)
51
51
- Falls back gracefully for non-cacheable codes (log and skip, do not throw)
Copy file name to clipboardExpand all lines: extension/mcp/prompts/handle_response.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ Follow these steps:
37
37
38
38
4.**Emit null-safe, idiomatic Dart**:
39
39
- Prefer `?.` and `??` over null-checks
40
-
- Use `const` callbacks with `whenConstStatusCode` / `whenConstOrNull` when the return values are constants
40
+
- Use `whenConstStatusCode` / `whenConstOrNull` when the return values are constants — these accept **direct values**, not closures (e.g. `isSuccess: 'ok'`, never `isSuccess: () => 'ok'`); they must be called on a `StatusCode` value after `toRegisteredStatusCode()` conversion
41
41
- Avoid `if (code >= 200 && code < 300)` — use `.isSuccess` / `.isError` / `.isCacheable` etc.
42
42
43
43
5.**Handle the specific code** {{#status_code}}({{status_code}}){{/status_code}} with a dedicated branch inside `maybeMap` or `maybeWhen` on the `StatusCode`, using the constant name `<camelName>Http<NNN>`.
0 commit comments