feat(sse): expand accepted HTTP status codes for SSE stream connection
Accept HTTP status codes 200, 201, 202, and 206 as valid responses for SSE stream connection. Improves error message to include actual status code. Removes unused main method. Resolves #68
This commit is contained in:
parent
a424b36653
commit
d75adb68c7
1 changed files with 3 additions and 28 deletions
|
|
@ -198,8 +198,9 @@ public class FlowSseClient {
|
|||
info -> subscriberFactory.apply(lineSubscriber));
|
||||
|
||||
future.thenAccept(response -> {
|
||||
if (response.statusCode() != 200) {
|
||||
throw new RuntimeException("Failed to connect to SSE stream: " + response.statusCode());
|
||||
int status = response.statusCode();
|
||||
if (status != 200 && status != 201 && status != 202 && status != 206) {
|
||||
throw new RuntimeException("Failed to connect to SSE stream. Unexpected status code: " + status);
|
||||
}
|
||||
}).exceptionally(throwable -> {
|
||||
eventHandler.onError(throwable);
|
||||
|
|
@ -207,30 +208,4 @@ public class FlowSseClient {
|
|||
});
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
|
||||
// FlowSseClient sseClient = new FlowSseClient(
|
||||
// HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build());
|
||||
|
||||
// var eventHandler = new SSEEventHandler() {
|
||||
// @Override
|
||||
// public void onEvent(SSEEvent event) {
|
||||
// System.out.println("Received event: " + event);
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public void onError(Throwable error) {
|
||||
// System.out.println("Error: " + error);
|
||||
// }
|
||||
// };
|
||||
// sseClient.subscribe("http://localhost:8080/sse", eventHandler);
|
||||
|
||||
// try {
|
||||
// Thread.sleep(100000);
|
||||
// }
|
||||
// catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue