Commit 0707b60
authored
feat!: report every SSE error response with status, headers, and recoverability (#311)
## ⚠ Breaking change
The SSE client now reports **recoverable** error responses (e.g. 5xx) on
the stream. Previously only unrecoverable responses surfaced and
recoverable ones were retried silently. A consumer that treats any error
from the stream as terminal will now tear down on a transient error — it
must check `SseHttpError.recoverable` and ignore recoverable errors (the
client retries those itself). `UnrecoverableStatusError` is removed; use
`SseHttpError` instead.
This bumps event_source to a major (2.2.0 → 3.0.0).
## What
Replaces `UnrecoverableStatusError` with `SseHttpError`, reported on the
event stream for **any** non-200 response — recoverable or not. It
carries:
- `statusCode`
- `headers` (always — may hold a service directive)
- `recoverable` — whether the client will retry on its own (backoff) or
has stopped
```dart
final class SseHttpError implements Exception {
final int statusCode;
final Map<String, String> headers;
final bool recoverable;
const SseHttpError(this.statusCode, this.headers, {required this.recoverable});
}
```
## Why
A LaunchDarkly streaming endpoint can deliver the FDv2-to-FDv1 fallback
directive (`x-ld-fd-fallback`) in the headers of an
*otherwise-retriable* error response (e.g. a 500). Previously
recoverable responses surfaced nothing, so that directive was invisible
and the client just kept reconnecting. Now every error response is
reported with its headers and a `recoverable` flag, and the consumer
decides what to do. This keeps the client a pure transport — it reports
what it saw rather than taking an injected retry policy. The browser
`EventSource` cannot observe responses and reports nothing, as before.
## Tests
`state_connecting` covers a recoverable error (backs off, reports
`recoverable: true` with headers) and an unrecoverable one (goes idle,
reports `recoverable: false` with headers).
---
First of a two-PR stack; the fallback behavior that consumes this is in
the stacked follow-up.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **High Risk**
> Breaking public API and stream semantics; downstream code that does
not check recoverable may incorrectly terminate connections on transient
HTTP errors.
>
> **Overview**
> **Breaking:** `UnrecoverableStatusError` is removed and replaced by
**`SseHttpError`**, which is emitted on the event stream for **every**
non-200 HTTP response (not only statuses the client will not retry).
>
> `SseHttpError` includes `statusCode`, `headers`, and
**`recoverable`**. When `recoverable` is `true`, the client still backs
off and reconnects, but it now **also** pushes the error on the stream
so consumers can read headers (e.g. `x-ld-fd-fallback`) on retriable
failures. When `recoverable` is `false`, behavior matches the old
unrecoverable path: idle with the error reported.
>
> Callers that treat **any** stream error as fatal must ignore errors
where `recoverable == true` or they will tear down on transient
5xx-style responses.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
21aa063. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 61a1e59 commit 0707b60
5 files changed
Lines changed: 71 additions & 28 deletions
File tree
- packages/event_source_client
- lib
- src
- test
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 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
5 | 12 | | |
6 | 13 | | |
7 | 14 | | |
8 | | - | |
9 | | - | |
10 | | - | |
| 15 | + | |
| 16 | + | |
11 | 17 | | |
12 | 18 | | |
13 | 19 | | |
14 | | - | |
15 | | - | |
| 20 | + | |
16 | 21 | | |
17 | 22 | | |
18 | | - | |
19 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
20 | 31 | | |
21 | 32 | | |
22 | | - | |
| 33 | + | |
| 34 | + | |
23 | 35 | | |
Lines changed: 14 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
67 | 72 | | |
68 | | - | |
69 | | - | |
| 73 | + | |
| 74 | + | |
70 | 75 | | |
71 | 76 | | |
72 | 77 | | |
| 78 | + | |
73 | 79 | | |
74 | 80 | | |
75 | 81 | | |
| |||
Lines changed: 29 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
| 34 | + | |
30 | 35 | | |
31 | | - | |
| 36 | + | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
35 | 47 | | |
36 | 48 | | |
37 | 49 | | |
38 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
39 | 53 | | |
| 54 | + | |
40 | 55 | | |
41 | 56 | | |
42 | 57 | | |
43 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
44 | 61 | | |
45 | 62 | | |
46 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
47 | 71 | | |
48 | 72 | | |
49 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
0 commit comments