(
action: string,
params: any,
sendResponse: (response: any) => void,
sender: RuntimeMessageSender
)
| 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 | |
| 234 | export class Group { |
no test coverage detected