Improved error message if the server can't read session recordings. (#4363)

Ylian Saint-Hilaire committed Aug 4, 2022 at 11:28 UTC 13c0afbc1ee13d2fc847f772c6dad805a1e110df
2 files changed +9 -4
meshuser.js
+3 -3
@@ -1025,11 +1025,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1025 if (domain.sessionrecording.filepath) { recordingsPath = domain.sessionrecording.filepath; } else { recordingsPath = parent.parent.recordpath; }
1026 if (recordingsPath == null) return;
1027 fs.readdir(recordingsPath, function (err, files) {
1028 - if (err != null) return;
1028 + if (err != null) { try { ws.send(JSON.stringify({ action: 'recordings', error: 1, tag: command.tag })); } catch (ex) { } return; }
1029 if ((command.limit == null) || (typeof command.limit != 'number')) {
1030 // Send the list of all recordings
1031 db.GetEvents(['recording'], domain.id, function (err, docs) {
1032 - if (err != null) return;
1032 + if (err != null) { try { ws.send(JSON.stringify({ action: 'recordings', error: 2, tag: command.tag })); } catch (ex) { } return; }
1033 for (var i in docs) {
1034 delete docs[i].action; delete docs[i].etype; delete docs[i].msg; // TODO: We could make a more specific query in the DB and never have these.
1035 if (files.indexOf(docs[i].filename) >= 0) { docs[i].present = 1; }
@@ -1039,7 +1039,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1039 } else {
1040 // Send the list of most recent recordings, up to 'limit' count
1041 db.GetEventsWithLimit(['recording'], domain.id, command.limit, function (err, docs) {
1042 - if (err != null) return;
1042 + if (err != null) { try { ws.send(JSON.stringify({ action: 'recordings', error: 2, tag: command.tag })); } catch (ex) { } return; }
1043 for (var i in docs) {
1044 delete docs[i].action; delete docs[i].etype; delete docs[i].msg; // TODO: We could make a more specific query in the DB and never have these.
1045 if (files.indexOf(docs[i].filename) >= 0) { docs[i].present = 1; }
views/default.handlebars
+6 -1
@@ -2728,6 +2728,7 @@
2728 }
2729 case 'recordings': {
2730 p52recordings = message.events;
2731 + if (message.error != null) { p52recordings = message.error; }
2732 updateRecordings();
2733 break;
2734 }
@@ -2986,7 +2987,7 @@
2987 break;
2988 }
2989 case 'recording': {
2989 - if (p52recordings != null) { p52recordings.unshift(message.event); message.event.present = 1; updateRecordings(); }
2990 + if ((p52recordings != null) && (typeof p52recordings == 'object')) { p52recordings.unshift(message.event); message.event.present = 1; updateRecordings(); }
2991 break;
2992 }
2993 case 'userWebState': {
@@ -15943,6 +15944,10 @@
15944
15945 if (p52recordings == null) {
15946 x += '<div style=width:100%;text-align:center;margin-top:20px><i>' + "Loading..." + '</i></div>';
15947 + } else if (typeof p52recordings == 'number') {
15948 + if (p52recordings == 1) { x += '<div style=width:100%;text-align:center;margin-top:20px><i>' + "Server is unable to read from the recordings folder." + '</i></div>'; }
15949 + else if (p52recordings == 2) { x += '<div style=width:100%;text-align:center;margin-top:20px><i>' + "Server is unable to get recordings from the database." + '</i></div>'; }
15950 + else { x += '<div style=width:100%;text-align:center;margin-top:20px><i>' + "An unknown error occured." + '</i></div>'; }
15951 } else if (p52recordings.length == 0) {
15952 x += '<div style=width:100%;text-align:center;margin-top:20px><i>' + "No recordings." + '</i></div>';
15953 } else {