fix: error handling
This commit is contained in:
+13
-9
@@ -356,17 +356,21 @@ router.post('/affiliations/:target', async function (req, res) {
|
||||
res.status(500).json({message: 'telnet connection is not established.'});
|
||||
} else {
|
||||
let response = await connection.send('muc:room(\"'+ target +'\"):set_affiliation(true, \"'+ user +'\", \"' + affiliation +'\");\n');
|
||||
let rawresults = response.split("\n");
|
||||
let mucresults = [];
|
||||
for (var i = 0; i < rawresults.length - 1 ; i++) {
|
||||
if ((rawresults[i].startsWith("\u0000| ") || rawresults[i].startsWith("\| ")) && !rawresults[i].startsWith("| OK") && !rawresults[i].startsWith("\u0000| Result") ) {
|
||||
console.log("adding: ", rawresults[i].split("| ")[1].split("\r")[0]);
|
||||
mucresults.push(rawresults[i].split("| ")[1].split("\r")[0]);
|
||||
if ((response.indexOf("nil value") > -1) || (response.indexOf("Fatal ") > -1)) {
|
||||
res.status(500).json(response);
|
||||
} else {
|
||||
let rawresults = response.split("\n");
|
||||
let mucresults = [];
|
||||
for (var i = 0; i < rawresults.length - 1 ; i++) {
|
||||
if ((rawresults[i].startsWith("\u0000| ") || rawresults[i].startsWith("\| ")) && !rawresults[i].startsWith("| OK") && !rawresults[i].startsWith("\u0000| Result") ) {
|
||||
console.log("adding: ", rawresults[i].split("| ")[1].split("\r")[0]);
|
||||
mucresults.push(rawresults[i].split("| ")[1].split("\r")[0]);
|
||||
}
|
||||
}
|
||||
console.log('async rawresult:', rawresults);
|
||||
console.log('async result:', mucresults);
|
||||
res.status(200).json(mucresults);
|
||||
}
|
||||
console.log('async rawresult:', rawresults);
|
||||
console.log('async result:', mucresults);
|
||||
res.status(200).json(mucresults);
|
||||
}
|
||||
} else {
|
||||
res.status(404).json({message: 'connection not available'});
|
||||
|
||||
Reference in New Issue
Block a user