logs: handle logs not found (logrotated)
we show an error message in the UI now
This commit is contained in:
@@ -55,7 +55,17 @@ export function create(origin, accessToken, type, id) {
|
||||
name: 'LogsModel',
|
||||
stream(lineHandler, errorHandler) {
|
||||
eventSource = new EventSource(`${origin}${streamApi}?lines=${INITIAL_STREAM_LINES}&access_token=${accessToken}`);
|
||||
eventSource.onerror = errorHandler;
|
||||
eventSource._lastMessage = null;
|
||||
eventSource.onerror = function ( /* uselessError */) {
|
||||
if (eventSource.readyState === EventSource.CLOSED) {
|
||||
// eventSource does not give us the HTTP error code. We have to resort to message count check and guess the reason
|
||||
const msg = eventSource._lastMessage === null ? `Logs unavailable. Maybe the logs were logrotated.` : `Connection closed.`;
|
||||
const e = new Error(msg);
|
||||
e.time = moment().format('MMM DD HH:mm:ss');
|
||||
e.html = ansiToHtml(e.message);
|
||||
errorHandler(e);
|
||||
}
|
||||
};
|
||||
// eventSource.onopen = function () { console.log('stream is open'); };
|
||||
eventSource.onmessage = function (message) {
|
||||
var data;
|
||||
@@ -69,6 +79,7 @@ export function create(origin, accessToken, type, id) {
|
||||
const time = data.realtimeTimestamp ? moment(data.realtimeTimestamp/1000).format('MMM DD HH:mm:ss') : '';
|
||||
const html = ansiToHtml(escapeHtml(typeof data.message === 'string' ? data.message : ab2str(data.message)));
|
||||
|
||||
eventSource._lastMessage = { time, html };
|
||||
lineHandler(time, html);
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user