Add more robust error handling to server
Changes:
- Use the proper RESTful HTTP status codes for all endpoints (e.g. 204 rather than 200 when the response body is empty)
- Add consistent and more helpful error messages
- Handle invalid route parameters by checking if jamid returns empty objects (e.g. invalid contact IDs)
- Use res.send() rather than res.json() for consistency
- Handle three new signals
GitLab: #111
Change-Id: I1d48dc4629995ab9a96bb2086a9aa91f81889598
diff --git a/server/src/routers/call-router.ts b/server/src/routers/call-router.ts
index 835bf66..96cd7ce 100644
--- a/server/src/routers/call-router.ts
+++ b/server/src/routers/call-router.ts
@@ -16,6 +16,7 @@
* <https://www.gnu.org/licenses/>.
*/
import { Router } from 'express';
+import { HttpStatusCode } from 'jami-web-common';
import { Container } from 'typedi';
import { Jamid } from '../jamid/jamid.js';
@@ -34,5 +35,11 @@
callRouter.get('/:callId', (req, res) => {
const callDetails = jamid.getCallDetails(res.locals.accountId, req.params.callId);
+
+ if (Object.keys(callDetails).length === 0) {
+ res.status(HttpStatusCode.NotFound).send('No such call found');
+ return;
+ }
+
res.send(callDetails);
});