kb-server 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -41,7 +41,7 @@ function createServer(params, options) {
|
|
|
41
41
|
// 使用自定义中间件
|
|
42
42
|
middlewares.forEach((middleware) => app.use(middleware));
|
|
43
43
|
// 注入SSE
|
|
44
|
-
handlers && app.use((0, sse_middleware_1.packSSE)(handlers, { log, ...resetSSE }));
|
|
44
|
+
handlers && app.use((0, sse_middleware_1.packSSE)(handlers, { authFn, log, ...resetSSE }));
|
|
45
45
|
// 注入API
|
|
46
46
|
app.use((0, api_middleware_1.packAPI)(apis, { authFn, log }));
|
|
47
47
|
return app;
|
|
@@ -119,7 +119,15 @@ const packSSE = (sseHandlers, options) => {
|
|
|
119
119
|
const response = (0, exports.createSSEMsg)("done", "[DONE]");
|
|
120
120
|
res.write(response, () => res.end());
|
|
121
121
|
};
|
|
122
|
-
|
|
122
|
+
try {
|
|
123
|
+
await execution(params, { push, close, abortController }, ctx);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
// 业务内部的 abort 不关注
|
|
127
|
+
if (error?.name === "AbortError")
|
|
128
|
+
return;
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
123
131
|
}
|
|
124
132
|
catch (rawError) {
|
|
125
133
|
logger_1.logger.error(rawError);
|
|
@@ -148,10 +156,7 @@ const packSSE = (sseHandlers, options) => {
|
|
|
148
156
|
},
|
|
149
157
|
};
|
|
150
158
|
const response = (0, exports.createSSEMsg)("error", JSON.stringify(errResponse));
|
|
151
|
-
// 完成响应
|
|
152
|
-
took = Date.now() - start;
|
|
153
159
|
logger_1.logger.info(`发送消息:\n${response}`);
|
|
154
|
-
logger_1.logger.info(`耗时:${took} ms - ${requestId}`);
|
|
155
160
|
res.write(response, () => res.end());
|
|
156
161
|
}
|
|
157
162
|
};
|