Report errors on downStream

This commit is contained in:
Chrystian Huot 2020-09-06 13:56:25 -04:00
parent 45d721da55
commit eaa77c0309
3 changed files with 15 additions and 17 deletions

View file

@ -91,11 +91,9 @@ class CallUpload {
const talkgroup = parseInt(reqBody.talkgroup, 10) || null;
if (!this.controller.validateApiKey(apiKey, system, talkgroup)) {
const message = `system=${system} talkgroup=${talkgroup} file=${audioName} No matching system/talkgroup`;
console.warn(`Api: system=${system} talkgroup=${talkgroup} file=${audioName} No matching system/talkgroup`);
console.warn(`Api: ${message}`);
res.send(`${message}\n`);
res.sendStatus(403);
return;
}
@ -117,7 +115,9 @@ class CallUpload {
res.send(`Call imported successfully.\n`);
} catch (error) {
res.status(500).send(error.message);
console.error(`Api: system=${system} talkgroup=${talkgroup} file=${audioName} ${error.message}`);
res.sendStatus(500);
}
}
});

View file

@ -403,15 +403,10 @@ class Controller extends EventEmitter {
let newCall;
try {
newCall = await this.models.call.create(call);
console.log(`NewCall: system=${call.system} talkgroup=${call.talkgroup} file=${call.audioName} Success`);
} catch (error) {
console.log(`NewCall: system=${call.system} talkgroup=${call.talkgroup} file=${call.audioName} ${error.message}`);
}
this.emit('call', newCall);
}

View file

@ -136,14 +136,17 @@ class Downstream {
form.append('system', call.system);
form.append('talkgroup', call.talkgroup);
form.submit(apiUrl, (error) => {
form.submit(apiUrl, (error, response) => {
const message = `Downstream: system=${call.system} talkgroup=${call.talkgroup} file=${call.audioName} to=${downstream.url}`;
if (error) {
console.log(`Downstream: system=${call.system} talkgroup=${call.talkgroup} `
+ `file=${call.audioName} to=${downstream.url} ${error.message}`);
console.error(`${message} ${error.message}`);
} else if (response.statusCode !== 200) {
console.error(`${message} ${response.statusMessage}`);
} else {
console.log(`Downstream: system=${call.system} talkgroup=${call.talkgroup} `
+ `file=${call.audioName} to=${downstream.url} Success`);
console.log(`${message} Success`);
}
});
}