Skip to content

Commit f84b2e9

Browse files
committed
https://github.com/langchain4j/langchain4j/pull/2906
1 parent 54a6b54 commit f84b2e9

File tree

1 file changed

+9
-4
lines changed
  • langchain4j-http-client-spring-restclient/src/main/java/dev/langchain4j/http/client/spring/restclient

1 file changed

+9
-4
lines changed

langchain4j-http-client-spring-restclient/src/main/java/dev/langchain4j/http/client/spring/restclient/SpringRestClient.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.InputStream;
2020
import java.net.SocketTimeoutException;
2121

22+
import static dev.langchain4j.http.client.sse.ServerSentEventListenerUtils.ignoringExceptions;
2223
import static dev.langchain4j.internal.Utils.getOrDefault;
2324

2425
public class SpringRestClient implements HttpClient {
@@ -96,26 +97,30 @@ public void execute(HttpRequest request, ServerSentEventParser parser, ServerSen
9697

9798
if (!springResponse.getStatusCode().is2xxSuccessful()) {
9899
String body = springResponse.bodyTo(String.class);
99-
listener.onError(new HttpException(statusCode, body));
100+
101+
HttpException exception = new HttpException(statusCode, body);
102+
ignoringExceptions(() -> listener.onError(exception));
100103
return null;
101104
}
102105

103106
SuccessfulHttpResponse response = SuccessfulHttpResponse.builder()
104107
.statusCode(statusCode)
105108
.headers(springResponse.getHeaders())
106109
.build();
107-
listener.onOpen(response);
110+
ignoringExceptions(() -> listener.onOpen(response));
108111

109112
try (InputStream inputStream = springResponse.getBody()) {
110113
parser.parse(inputStream, listener);
111-
listener.onClose();
114+
ignoringExceptions(listener::onClose);
112115
}
113116

114117
return null;
115118
});
116119
} catch (Exception e) {
117120
if (e.getCause() instanceof SocketTimeoutException) {
118-
listener.onError(new TimeoutException(e));
121+
ignoringExceptions(() -> listener.onError(new TimeoutException(e)));
122+
} else {
123+
ignoringExceptions(() -> listener.onError(e));
119124
}
120125
}
121126
});

0 commit comments

Comments
 (0)