Skip to content

Commit 44e020d

Browse files
committed
Handle Errors
1 parent 24db7da commit 44e020d

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

public/electron.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,14 @@ async function createWindow() {
7979
});
8080

8181
ipcMain.on("terminal:command", async (event, command) => {
82-
var output = await sendArbitraryCommand(selectedShell, command);
83-
output = parseMultiline(output);
84-
event.reply("terminal:command-reply", output);
82+
try {
83+
var output = await sendArbitraryCommand(selectedShell, command);
84+
output = parseMultiline(output);
85+
event.reply("terminal:command-reply", output);
86+
} catch(err) {
87+
console.log(err);
88+
event.reply("misc:alert", {alertType: "warning", alertMessage: "Failed to send command!"});
89+
}
8590
});
8691

8792
// Listen for window being closed

public/utils/requests.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,23 @@ const sendRequest = async (shell, reqType) => {
8787

8888
/** @exports */
8989
const sendArbitraryCommand = async (shell, command) => {
90-
var request = encodeCommand(command, shell.commandEncoding);
90+
try {
91+
var request = encodeCommand(command, shell.commandEncoding);
9192

92-
const config = generateConfig(shell, request);
93-
var response;
93+
const config = generateConfig(shell, request);
94+
var response;
9495

95-
if(shell.commandParamType === "POST") {
96-
response = await axios.post(shell.ipOrHostname, config);
97-
} else {
98-
response = await axios.get(shell.ipOrHostname, config);
99-
}
96+
if(shell.commandParamType === "POST") {
97+
response = await axios.post(shell.ipOrHostname, config);
98+
} else {
99+
response = await axios.get(shell.ipOrHostname, config);
100+
}
100101

101-
return response;
102+
return response;
103+
} catch (error) {
104+
return null;
105+
}
106+
102107
}
103108

104109
/**
@@ -159,4 +164,4 @@ const workingDir = async (shell) => {
159164
return dirName;
160165
};
161166

162-
module.exports = { sendRequest, sendArbitraryRequest, determineOS, listDir, workingDir };
167+
module.exports = { sendRequest, sendArbitraryCommand, determineOS, listDir, workingDir };

0 commit comments

Comments
 (0)