Update generate failed and set status code
This commit is contained in:
parent
2996a6056e
commit
d54b69ce80
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cubetiq/hlt",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"description": "A lightweight http tunnel client using nodejs and socket.io client",
|
||||
"main": "dist/client.js",
|
||||
"bin": {
|
||||
|
@ -265,6 +265,7 @@ program
|
||||
config.apiKey = options.key;
|
||||
}
|
||||
|
||||
let errorCode = 0;
|
||||
if (!config.token || options.force) {
|
||||
console.log("Generating token...");
|
||||
await getTokenFree(config.server, {
|
||||
@ -273,22 +274,26 @@ program
|
||||
apiKey: config.apiKey,
|
||||
})
|
||||
.then((resp: any) => {
|
||||
console.log("Token generated successfully!");
|
||||
if (resp.data?.token) {
|
||||
console.log("Token generated successfully!");
|
||||
config.token = resp.data?.token;
|
||||
} else {
|
||||
console.log("free token return with null or empty from server");
|
||||
errorCode = 1;
|
||||
console.error("Generate free token failed, return with null or empty from server!", resp);
|
||||
return;
|
||||
}
|
||||
})
|
||||
.catch((err: any) => {
|
||||
errorCode = 1;
|
||||
console.error("cannot get free token from server", err);
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2));
|
||||
console.log(`initialized config saved successfully to: ${configFilePath}`);
|
||||
if (errorCode === 0) {
|
||||
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2));
|
||||
console.log(`initialized config saved successfully to: ${configFilePath}`);
|
||||
}
|
||||
});
|
||||
|
||||
// start
|
||||
@ -407,6 +412,9 @@ program
|
||||
config.server = SERVER_DEFAULT_URL;
|
||||
}
|
||||
|
||||
// Error Code status
|
||||
let errorCode = 0;
|
||||
|
||||
if (type === "token" || type === "jwt") {
|
||||
config.token = value;
|
||||
} else if (type === "server") {
|
||||
@ -430,11 +438,13 @@ program
|
||||
if (resp.data?.token) {
|
||||
config.token = resp.data?.token;
|
||||
} else {
|
||||
console.log("free token return with null or empty from server");
|
||||
errorCode = 1;
|
||||
console.error("Generate free token failed, return with null or empty from server!", resp);
|
||||
return;
|
||||
}
|
||||
})
|
||||
.catch((err: any) => {
|
||||
errorCode = 1;
|
||||
console.error("cannot get free token from server", err);
|
||||
return;
|
||||
});
|
||||
@ -445,8 +455,10 @@ program
|
||||
config.clientId = config.apiKey;
|
||||
}
|
||||
|
||||
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2));
|
||||
console.log(`${type} config saved successfully to: ${configFilePath}`);
|
||||
if (errorCode === 0) {
|
||||
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2));
|
||||
console.log(`${type} config saved successfully to: ${configFilePath}`);
|
||||
}
|
||||
});
|
||||
|
||||
// config
|
||||
|
Loading…
Reference in New Issue
Block a user