diff --git a/dashboard/src/js/client.js b/dashboard/src/js/client.js index c49ba2ac1..51e8ebe88 100644 --- a/dashboard/src/js/client.js +++ b/dashboard/src/js/client.js @@ -1407,7 +1407,8 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout Client.prototype.getTaskLogs = function (taskId, follow, lines, callback) { if (follow) { var eventSource = new EventSource(client.apiOrigin + '/api/v1/tasks/' + taskId + '/logstream?lines=' + lines + '&access_token=' + token); - callback(null, eventSource); + eventSource.onerror = callback; + eventSource.onopen = function () { callback(null, eventSource); }; } else { get('/api/v1/services/' + taskId + '/logs?lines=' + lines, null, function (error, data, status) { if (error) return callback(error); @@ -1544,7 +1545,8 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout Client.prototype.getPlatformLogs = function (unit, follow, lines, callback) { if (follow) { var eventSource = new EventSource(client.apiOrigin + '/api/v1/cloudron/logstream/' + unit + '?lines=' + lines + '&access_token=' + token); - callback(null, eventSource); + eventSource.onerror = callback; + eventSource.onopen = function () { callback(null, eventSource); }; } else { get('/api/v1/cloudron/logs/' + unit + '?lines=' + lines, null, function (error, data, status) { if (error) return callback(error); @@ -1558,7 +1560,8 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout Client.prototype.getServiceLogs = function (serviceName, follow, lines, callback) { if (follow) { var eventSource = new EventSource(client.apiOrigin + '/api/v1/services/' + serviceName + '/logstream?lines=' + lines + '&access_token=' + token); - callback(null, eventSource); + eventSource.onerror = callback; + eventSource.onopen = function () { callback(null, eventSource); }; } else { get('/api/v1/services/' + serviceName + '/logs?lines=' + lines, null, function (error, data, status) { if (error) return callback(error); @@ -1588,7 +1591,8 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout Client.prototype.getAppLogs = function (appId, follow, lines, callback) { if (follow) { var eventSource = new EventSource(client.apiOrigin + '/api/v1/apps/' + appId + '/logstream?lines=' + lines + '&access_token=' + token); - callback(null, eventSource); + eventSource.onerror = callback; + eventSource.onopen = function () { callback(null, eventSource); }; } else { get('/api/v1/apps/' + appId + '/logs', null, function (error, data, status) { if (error) return callback(error); diff --git a/dashboard/src/js/logs.js b/dashboard/src/js/logs.js index ccf6fdf20..7555f2f1c 100644 --- a/dashboard/src/js/logs.js +++ b/dashboard/src/js/logs.js @@ -17,7 +17,7 @@ app.controller('LogsController', ['$scope', '$translate', 'Client', function ($s $scope.lines = 100; $scope.selectedAppInfo = null; $scope.selectedTaskInfo = null; - $scope.error = false; + $scope.error = null; function ab2str(buf) { return String.fromCharCode.apply(null, new Uint16Array(buf)); @@ -55,8 +55,11 @@ app.controller('LogsController', ['$scope', '$translate', 'Client', function ($s else if ($scope.selected.type === 'task') func = Client.getTaskLogs; else if ($scope.selected.type === 'app') func = Client.getAppLogs; - func($scope.selected.value, true /* follow */, $scope.lines, function handleLogs(error, result) { - if (error) return console.error(error); + func($scope.selected.value, true /* follow */, $scope.lines, function (error, result) { + if (error) { + $scope.$apply(function () { $scope.error = { logsGone: true }; }); + return console.error('Error subscribing to logstream.', error); + } $scope.activeEventSource = result; result.onmessage = function handleMessage(message) { @@ -184,8 +187,8 @@ app.controller('LogsController', ['$scope', '$translate', 'Client', function ($s $scope.initialized = true; if (error) { - $scope.error = true; - return Client.initError(error, init); + $scope.error = { notFound: true }; + return console.error('Not found.', error); } // now mark the Client to be ready diff --git a/dashboard/src/logs.html b/dashboard/src/logs.html index 04348d79d..b6ec13706 100644 --- a/dashboard/src/logs.html +++ b/dashboard/src/logs.html @@ -65,7 +65,8 @@ {{ 'main.offline' | tr }}
-
{{ 'logs.notFoundError' | tr }}
+
{{ 'logs.notFoundError' | tr }}
+
{{ 'logs.logsGoneError' | tr }}

{{ selected.name }}

diff --git a/dashboard/src/translation/en.json b/dashboard/src/translation/en.json index 80a36c8d8..33ce1efbb 100644 --- a/dashboard/src/translation/en.json +++ b/dashboard/src/translation/en.json @@ -1073,7 +1073,8 @@ "title": "Logs", "clear": "Clear View", "download": "Download Full Logs", - "notFoundError": "No such task or app" + "notFoundError": "No such task or app", + "logsGoneError": "Corresponding log files are already gone" }, "terminal": { "title": "Terminal",