( ctx: RouterContext, err: Error | string, config?: IResponseErrorConfig )
| 48 | } |
| 49 | |
| 50 | export function responseError( |
| 51 | ctx: RouterContext, |
| 52 | err: Error | string, |
| 53 | config?: IResponseErrorConfig |
| 54 | ) { |
| 55 | let errinfo: any = ""; |
| 56 | if (err) errinfo = err.toString(); |
| 57 | else errinfo = err; |
| 58 | const packet = new Packet(ctx.uuid, STATUS_ERR, ctx.event, errinfo); |
| 59 | // Ignore |
| 60 | if (String(err).includes(IGNORE) && ctx.event) return ctx.socket.emit(ctx.event, packet); |
| 61 | if (!config?.disablePrint) |
| 62 | logger.warn( |
| 63 | $t("TXT_CODE_protocol.socketErr", { |
| 64 | id: ctx.socket.id, |
| 65 | address: ctx.socket.handshake.address, |
| 66 | event: ctx.event |
| 67 | }), |
| 68 | err |
| 69 | ); |
| 70 | if (ctx.event) ctx.socket.emit(ctx.event, packet); |
| 71 | } |
| 72 | |
| 73 | export function msg(ctx: RouterContext, event: string, data: any) { |
| 74 | const packet = new Packet(ctx.uuid, STATUS_OK, event, data); |
no test coverage detected