Update cookbook/copilot-sdk/java/recipe/ErrorHandling.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Bruno Borges
2026-04-06 16:31:10 -04:00
committed by GitHub
parent 6f47a3d1d2
commit 8f570c0d89

View File

@@ -11,18 +11,17 @@ public class ErrorHandling {
try (var client = new CopilotClient()) { try (var client = new CopilotClient()) {
client.start().get(); client.start().get();
var session = client.createSession( try (var session = client.createSession(
new SessionConfig() new SessionConfig()
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL) .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setModel("gpt-5")).get(); .setModel("gpt-5")).get()) {
session.on(AssistantMessageEvent.class, session.on(AssistantMessageEvent.class,
msg -> System.out.println(msg.getData().content())); msg -> System.out.println(msg.getData().content()));
session.sendAndWait( session.sendAndWait(
new MessageOptions().setPrompt("Hello!")).get(); new MessageOptions().setPrompt("Hello!")).get();
}
session.close();
} catch (ExecutionException ex) { } catch (ExecutionException ex) {
Throwable cause = ex.getCause(); Throwable cause = ex.getCause();
Throwable error = cause != null ? cause : ex; Throwable error = cause != null ? cause : ex;