catching more errors

This commit is contained in:
Luke Berndt
2023-04-10 15:53:24 -04:00
parent 1fce1d5eef
commit 4de89c9ac2
2 changed files with 18 additions and 16 deletions

View File

@@ -6,7 +6,7 @@ var Talkgroup = require("../models/talkgroup");
var { callModel: Call } = require("../models/call"); var { callModel: Call } = require("../models/call");
const { PutObjectCommand, S3Client } = require("@aws-sdk/client-s3"); const { PutObjectCommand, S3Client } = require("@aws-sdk/client-s3");
const {fromIni} = require("@aws-sdk/credential-providers"); const { fromIni } = require("@aws-sdk/credential-providers");
var s3_endpoint = process.env['S3_ENDPOINT'] != null ? process.env['S3_ENDPOINT'] : 'https://s3.us-west-1.wasabisys.com'; var s3_endpoint = process.env['S3_ENDPOINT'] != null ? process.env['S3_ENDPOINT'] : 'https://s3.us-west-1.wasabisys.com';
var s3_region = process.env['S3_REGION'] != null ? process.env['S3_REGION'] : 'us-west-1'; var s3_region = process.env['S3_REGION'] != null ? process.env['S3_REGION'] : 'us-west-1';
@@ -144,9 +144,13 @@ exports.upload = async function (req, res, next) {
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
let s3Src;
var s3Src = fs.createReadStream(req.file.path); try {
s3Src = fs.createReadStream(req.file.path);
} catch (err) {
console.error("[" + call.shortName + "] Unable to open file: " + req.file.path)
return;
}
const command = new PutObjectCommand({ const command = new PutObjectCommand({
Bucket: s3_bucket, Bucket: s3_bucket,
Key: object_key, Key: object_key,

View File

@@ -247,7 +247,7 @@ function notify_clients(call) {
io.sockets.on('connection', function (client) { io.sockets.on('connection', function (client) {
clients[client.id] = { socket: client, active: false }; clients[client.id] = { socket: client, active: false };
clients[client.id].timestamp = new Date(); clients[client.id].timestamp = new Date();
client.on('start', function (data) { client.on('start', async function (data) {
if (clients[client.id] && data.shortName) { if (clients[client.id] && data.shortName) {
clients[client.id].active = true; clients[client.id].active = true;
clients[client.id].shortName = data.shortName.toLowerCase(); clients[client.id].shortName = data.shortName.toLowerCase();
@@ -258,8 +258,8 @@ io.sockets.on('connection', function (client) {
clients[client.id].talkgroupNums = []; clients[client.id].talkgroupNums = [];
clients[client.id].timestamp = new Date(); clients[client.id].timestamp = new Date();
if ((data.filterType == "group") && (data.filterCode.indexOf(',') == -1)) { if ((data.filterType == "group") && (data.filterCode.indexOf(',') == -1)) {
db.get().collection("groups", function (err, groupCollection) { const groupCollection = db.get().collection("groups");
if (err || !groupCollection) { if (!groupCollection) {
console.error("Error - unable to open groups collection: " + err); console.error("Error - unable to open groups collection: " + err);
delete clients[client.id]; delete clients[client.id];
return; return;
@@ -269,15 +269,16 @@ io.sockets.on('connection', function (client) {
delete clients[client.id]; delete clients[client.id];
return; return;
} }
groupCollection.findOne({ try {
const group = await groupCollection.findOne({
'shortName': data.shortName.toLowerCase(), 'shortName': data.shortName.toLowerCase(),
'_id': ObjectId.createFromHexString(data.filterCode) '_id': ObjectId.createFromHexString(data.filterCode)
}, function (err, group) { });
if (err) { } catch (err) {
console.warn("[" + data.shortName.toLowerCase() + "] Error - WebSocket Group ID not Found! Error: " + err + " Group ID: " + data.filterCode); console.warn("[" + data.shortName.toLowerCase() + "] Error - WebSocket Group ID not Found! Error: " + err + " Group ID: " + data.filterCode);
delete clients[client.id]; delete clients[client.id];
return; return;
} else { }
if (group && clients[client.id]) { if (group && clients[client.id]) {
clients[client.id].talkgroupNums = group.talkgroups; clients[client.id].talkgroupNums = group.talkgroups;
} else { } else {
@@ -285,11 +286,8 @@ io.sockets.on('connection', function (client) {
delete clients[client.id]; delete clients[client.id];
return; return;
} }
}
});
});
} if ((data.filterType == "talkgroup") && Array.isArray(data.filterCode)) { } else if ((data.filterType == "talkgroup") && Array.isArray(data.filterCode)) {
clients[client.id].talkgroupNums = data.filterCode; clients[client.id].talkgroupNums = data.filterCode;
} }
//console.log("[" + data.shortName.toLowerCase() + "] WebSocket Updating - Client: " + client.id + " code set to: " + data.filterCode + " type set to: " + data.filterType + " TGS: " + clients[client.id].talkgroupNums); //console.log("[" + data.shortName.toLowerCase() + "] WebSocket Updating - Client: " + client.id + " code set to: " + data.filterCode + " type set to: " + data.filterType + " TGS: " + clients[client.id].talkgroupNums);