Skip to content

Commit c4e0bfd

Browse files
committed
feat(sse): expose terminal subscription failure
1 parent 1d6cb16 commit c4e0bfd

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎src/main/java/io/github/easy4j/hermes/api/sse/SseSubscription.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public final class SseSubscription implements AutoCloseable {
2222
* 首次取消订阅时执行的底层清理动作。
2323
*/
2424
private final Runnable cancellation;
25+
private final AtomicReference<Throwable> terminalError = new AtomicReference<>();
2526
private final AtomicReference<SseContinuityStatus> continuityStatus =
2627
new AtomicReference<>(SseContinuityStatus.INITIAL);
2728

@@ -68,6 +69,18 @@ public SseContinuityStatus getContinuityStatus() {
6869
return continuityStatus.get();
6970
}
7071

72+
/** Returns the terminal observation error, or null when none has been recorded. */
73+
public Throwable getTerminalError() {
74+
return terminalError.get();
75+
}
76+
77+
/** Records the first terminal observation error without replacing an earlier cause. */
78+
public void recordTerminalError(Throwable error) {
79+
if (error != null) {
80+
terminalError.compareAndSet(null, error);
81+
}
82+
}
83+
7184
/** Marks that this subscription has reattached without verified replay continuity. */
7285
public void markContinuityUnverified() {
7386
continuityStatus.compareAndSet(SseContinuityStatus.INITIAL, SseContinuityStatus.UNVERIFIED);

0 commit comments

Comments
 (0)