Skip to content

Commit 8f6253f

Browse files
committed
优化 web 异常得理
1 parent 18637c0 commit 8f6253f

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

soloncode-cli/src/main/java/org/noear/solon/codecli/portal/WebController.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,23 @@ public Result<List<Map>> commands() {
649649
* */
650650
@Mapping("/chat/input")
651651
public void chat_input(Context ctx, String input, UploadedFile[] attachments, String attachmentTypes[], String model, String sessionId) throws Throwable {
652+
try {
653+
chat_input_do(ctx, input, attachments, attachmentTypes, model, sessionId);
654+
} catch (Throwable e) {
655+
ctx.contentType(MimeType.TEXT_EVENT_STREAM_UTF8_VALUE);
656+
Flux<String> commandFlux = Flux.create(sink -> {
657+
ONode chunk = new ONode();
658+
chunk.set("type", "error");
659+
chunk.set("text", "! Error: " + e.getMessage());
660+
sink.next(chunk.toJson());
661+
sink.next("[DONE]");
662+
sink.complete();
663+
});
664+
ctx.returnValue(commandFlux);
665+
}
666+
}
667+
668+
private void chat_input_do(Context ctx, String input, UploadedFile[] attachments, String attachmentTypes[], String model, String sessionId) throws Throwable {
652669
if (sessionId == null || sessionId.isEmpty()) {
653670
sessionId = ctx.headerOrDefault("X-Session-Id", "web");
654671
}

0 commit comments

Comments
 (0)