MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / messageHandle

Method messageHandle

packages/message/server.ts:196–231  ·  view source on GitHub ↗
(
    action: string,
    params: any,
    sendResponse: (response: any) => void,
    sender: RuntimeMessageSender
  )

Source from the content-addressed store, hash-verified

194 }
195
196 private messageHandle(
197 action: string,
198 params: any,
199 sendResponse: (response: any) => void,
200 sender: RuntimeMessageSender
201 ) {
202 const func = this.apiFunctionMap.get(action);
203 if (func) {
204 try {
205 const ret = func(params, new SenderRuntime(sender));
206 if (ret instanceof Promise) {
207 ret
208 .then((data) => {
209 try {
210 sendResponse({ code: 0, data });
211 } catch (e: any) {
212 this.logger.error("sendResponse error", Logger.E(e));
213 }
214 })
215 .catch((e: Error) => {
216 sendResponse({ code: -1, message: formatErrorToClient(e) });
217 this.logger.error("messageHandle error", Logger.E(e));
218 });
219 return true;
220 } else {
221 sendResponse({ code: 0, data: ret });
222 }
223 } catch (e: any) {
224 sendResponse({ code: -1, message: formatErrorToClient(e) });
225 this.logger.error("messageHandle error", Logger.E(e));
226 }
227 } else {
228 sendResponse({ code: -1, message: "no such api " + action });
229 this.logger.error("no such api", { action: action });
230 }
231 }
232}
233
234export class Group {

Callers 3

constructorMethod · 0.95
server.test.tsFile · 0.45

Calls 5

funcFunction · 0.85
formatErrorToClientFunction · 0.85
errorMethod · 0.80
EMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected