99import org .apache .commons .lang3 .ObjectUtils ;
1010import org .devlive .sdk .openai .response .CompleteResponse ;
1111import org .devlive .sdk .openai .utils .JsonUtils ;
12- import org .jetbrains .annotations .NotNull ;
13- import org .jetbrains .annotations .Nullable ;
1412
1513import java .time .LocalDateTime ;
1614import java .util .concurrent .CountDownLatch ;
@@ -24,22 +22,22 @@ public class ConsoleEventSourceListener
2422 private JsonUtils <CompleteResponse > jsonUtils ;
2523
2624 @ Override
27- public void onOpen (@ NotNull EventSource eventSource , @ NotNull Response response )
25+ public void onOpen (EventSource eventSource , Response response )
2826 {
2927 log .info ("Console listener opened on time {}" , LocalDateTime .now ());
3028 this .jsonUtils = JsonUtils .getInstance ();
3129 }
3230
3331 @ Override
34- public void onClosed (@ NotNull EventSource eventSource )
32+ public void onClosed (EventSource eventSource )
3533 {
3634 log .info ("Console listener closed on time {}" , LocalDateTime .now ());
3735 eventSource .cancel ();
3836 this .close ();
3937 }
4038
4139 @ Override
42- public void onEvent (@ NotNull EventSource eventSource , @ Nullable String id , @ Nullable String type , @ NotNull String data )
40+ public void onEvent (EventSource eventSource , String id , String type , String data )
4341 {
4442 // OpenAI ends with [DONE] by default
4543 if (data .equals ("[DONE]" )) {
@@ -58,14 +56,19 @@ public void onEvent(@NotNull EventSource eventSource, @Nullable String id, @Null
5856 }
5957
6058 @ Override
61- public void onFailure (@ NotNull EventSource eventSource , @ Nullable Throwable throwable , @ Nullable Response response )
59+ public void onFailure (EventSource eventSource , Throwable throwable , Response response )
6260 {
63- if (throwable .getMessage ().endsWith ("CANCEL" )) {
64- log .info ("Console listener cancelled on time {}" , LocalDateTime .now ());
65- this .onClosed (eventSource );
61+ if (ObjectUtils .isNotEmpty (throwable )) {
62+ if (throwable .getMessage ().endsWith ("CANCEL" )) {
63+ log .info ("Console listener cancelled on time {}" , LocalDateTime .now ());
64+ this .onClosed (eventSource );
65+ }
66+ else {
67+ log .error ("Console listener throwable \n {}\n response: \n {}\n " , throwable , response );
68+ }
6669 }
6770 else {
68- log .error ("Console listener throwable \n {} \n response : \n {}\n " , throwable , response );
71+ log .error ("Console listener failure with empty throwable. Response : \n {}\n " , response );
6972 }
7073 eventSource .cancel ();
7174 this .close ();
0 commit comments