Add log type when error and warn

This commit is contained in:
Sambo Chea 2022-11-15 18:59:04 +07:00
parent 775b7b287b
commit 71432d7194
Signed by: sombochea
GPG Key ID: 3C7CF22A05D95490
2 changed files with 6 additions and 4 deletions

View File

@ -8,6 +8,7 @@
},
"scripts": {
"start": "ts-node-dev --respawn --transpile-only src/client.ts",
"local": "ts-node-dev --respawn --transpile-only src/client.ts start -p local",
"build": "tsc"
},
"repository": {

View File

@ -98,7 +98,7 @@ function initClient(options: any) {
});
socket.on("connect_error", (e) => {
console.log(
console.error(
`${clientLogPrefix} connect error:`,
(e && e.message) || "something wrong"
);
@ -108,11 +108,11 @@ function initClient(options: any) {
});
socket.on("disconnect", (reason) => {
console.log(`${clientLogPrefix} disconnected: ${reason}!`);
console.warn(`${clientLogPrefix} disconnected: ${reason}!`);
});
socket.on("disconnect_exit", (reason) => {
console.log(`${clientLogPrefix} disconnected and exited ${reason}!`);
console.warn(`${clientLogPrefix} disconnected and exited ${reason}!`);
socket?.disconnect();
process.exit(1);
});
@ -133,6 +133,7 @@ function initClient(options: any) {
tunnelRequest.pipe(localReq);
const onTunnelRequestError = (e: any) => {
console.error("tunnel request error: ", e);
tunnelRequest.off("end", onTunnelRequestEnd);
localReq.destroy(e);
};
@ -164,7 +165,7 @@ function initClient(options: any) {
};
const onLocalError = (error: any) => {
console.log(error);
console.error("local error:", error);
localReq.off("response", onLocalResponse);
socket?.emit("request-error", requestId, error && error.message);
tunnelRequest.destroy(error);