xhr测试
Some checks failed
build / Build (push) Failing after 10s
test / Run tests (push) Failing after 10s

This commit is contained in:
2025-02-05 18:01:59 +08:00
parent 8dd5bdaa56
commit 65b231911e
11 changed files with 199 additions and 12 deletions

View File

@ -3,7 +3,7 @@ import { Message, MessageConnect } from "./server";
export async function sendMessage(msg: Message, action: string, data?: any): Promise<any> {
const res = await msg.sendMessage({ action, data });
LoggerCore.getInstance().logger().debug("sendMessage", { action, data, res });
LoggerCore.getInstance().logger().debug("sendMessage", { action, data, response: res });
if (res && res.code) {
console.error(res);
return Promise.reject(res.message);

View File

@ -1,3 +1,5 @@
import LoggerCore from "@App/app/logger/core";
export interface Message {
onConnect(callback: (data: any, con: MessageConnect) => void): void;
onMessage(callback: (data: any, sendResponse: (data: any) => void) => void): void;
@ -50,6 +52,8 @@ export class Server {
}
private messageHandle(msg: string, params: any, sendResponse: (response: any) => void) {
const logger = LoggerCore.getInstance().logger({ env: this.env, msg });
logger.debug("messageHandle", { params });
const func = this.apiFunctionMap.get(msg);
if (func) {
try {
@ -65,6 +69,9 @@ export class Server {
} catch (e: any) {
sendResponse({ code: -1, message: e.message });
}
} else {
sendResponse({ code: -1, message: "no such api" });
logger.error("no such api");
}
}
}