Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit e48a32c

Browse files
committed
### Version 0.48.0 (Capture HTTP ERRORS in logs)
#### Feature - Capture all HTTP ERRORS in logs #### Fix - (Really) Fix Help > Open Error Log... to not duplicate errors - Catch publication wizard error in Resources dialog to allow app to continue without spinning loading forever. (Merge branch 'more_http_error_logs')
2 parents 1a7fb33 + 4e0a9a8 commit e48a32c

7 files changed

+94
-11
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
### Version 0.48.0 (Capture HTTP ERRORS in logs)
2+
3+
#### Feature
4+
5+
- Capture all HTTP ERRORS in logs
6+
7+
#### Fix
8+
9+
- (Really) Fix Help > Open Error Log... to not duplicate errors
10+
- Catch publication wizard error in Resources dialog to allow app to continue without spinning loading forever.
11+
112
### Version 0.47.5 (Fix logs)
213

314
#### Fix

app/constants/dblDotLocal.constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const dblDotLocalConfig = {
33
FLASK_API_DEFAULT: 'http://127.0.0.1:44151',
44
DDL_APP_LOG_PREFIX: 'dbl_dot_local_app',
55
DDL_APPENDER_ID: 'DDL',
6+
HTTP_ERROR_APPENDER_ID: 'HTTP_ERROR',
67
DDL_ERROR_LOG_BACKGROUND_COLOR: '#FFBABA',
78
DDL_ERROR_LOG_FONT_COLOR: '#CC0000',
89
DDL_ERROR_LOG_COUNT_INCREMENT: 'DDL_ERROR_LOG_COUNT_INCREMENT',
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const ipcRendererConstants = {
22
KEY_IPC_NAVIGATE: 'navigate',
3-
KEY_IPC_USER_AUTHENTICATION: 'userAuthentication'
3+
KEY_IPC_USER_AUTHENTICATION: 'userAuthentication',
4+
KEY_IPC_HTTP_ERROR_DATA: 'HTTP_ERROR_DATA'
45
};
56

67
export default ipcRendererConstants;

app/helpers/log.helpers.js

+25-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ import path from 'path';
33
import log4js from 'log4js';
44
import { browserWindowService } from '../services/browserWindow.service';
55
import dblDotLocalConstants from '../constants/dblDotLocal.constants';
6+
import { ipcRendererConstants } from '../constants/ipcRenderer.constants';
7+
8+
const { ipcRenderer } = require('electron');
9+
if (ipcRenderer) {
10+
ipcRenderer.on(ipcRendererConstants.KEY_IPC_HTTP_ERROR_DATA, (event, errorDetails) => {
11+
const detailsWithMaskedToken = errorDetails.url.startsWith(
12+
`${dblDotLocalConstants.FLASK_API_DEFAULT}/events/`
13+
)
14+
? {
15+
...errorDetails,
16+
url: `${dblDotLocalConstants.FLASK_API_DEFAULT}/events/...`
17+
}
18+
: errorDetails;
19+
log.error(detailsWithMaskedToken, { [dblDotLocalConstants.HTTP_ERROR_APPENDER_ID]: true });
20+
});
21+
}
622

723
export const logHelpers = {
824
setupLogFile,
@@ -54,6 +70,7 @@ function setupRendererErrorLogs() {
5470
const errorLogPath = getErrorLogPath();
5571
const generalAppenderId = 'NAT';
5672
const ddlAppenderId = dblDotLocalConstants.DDL_APPENDER_ID;
73+
const httpErrorAppenderId = dblDotLocalConstants.HTTP_ERROR_APPENDER_ID;
5774

5875
log4js.configure({
5976
appenders: {
@@ -63,7 +80,8 @@ function setupRendererErrorLogs() {
6380
maxLogSize: 1048576,
6481
backups: 3
6582
},
66-
[ddlAppenderId]: { type: 'file', filename: errorLogPath }
83+
[ddlAppenderId]: { type: 'file', filename: errorLogPath },
84+
[httpErrorAppenderId]: { type: 'file', filename: errorLogPath }
6785
},
6886
categories: {
6987
default: { appenders: [generalAppenderId], level: 'error' }
@@ -72,17 +90,20 @@ function setupRendererErrorLogs() {
7290

7391
const generalErrorLogger = log4js.getLogger(generalAppenderId);
7492
const ddlErrorLogger = log4js.getLogger(ddlAppenderId);
93+
const httpErrorLogger = log4js.getLogger(httpErrorAppenderId);
7594

7695
function errorHook(msg, transport) {
7796
if (transport !== log.transports.file || msg.level !== 'error') {
7897
return msg;
7998
}
8099
const msgData = msg.data[0];
81100
const tags = msg.data[1] || {};
82-
if (
101+
if (tags[httpErrorAppenderId]) {
102+
httpErrorLogger.error(msgData);
103+
} else if (
104+
tags[ddlAppenderId] ||
83105
(typeof msgData === 'string' &&
84-
msgData.startsWith(`${dblDotLocalConstants.DDL_APP_LOG_PREFIX}`)) ||
85-
tags[ddlAppenderId]
106+
msgData.startsWith(`${dblDotLocalConstants.DDL_APP_LOG_PREFIX}`))
86107
) {
87108
ddlErrorLogger.error(msgData);
88109
} else {

app/main.dev.js

+53-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import path from 'path';
1717
import MenuBuilder from './menu';
1818
import { autoUpdaterServices } from './main-process/autoUpdater.services';
1919
import { navigationConstants } from './constants/navigation.constants';
20+
import { ipcRendererConstants } from './constants/ipcRenderer.constants';
2021
import { logHelpers } from './helpers/log.helpers';
2122

2223
/*
@@ -135,8 +136,60 @@ app.on('ready', async () => {
135136
// eslint-disable-next-line no-underscore-dangle
136137
`autoUpdater config path: ${myAutoUpdater._appUpdateConfigPath}`
137138
);
139+
attachDebugger();
138140
});
139141

142+
function sendErrorToMainWindow({
143+
url,
144+
method,
145+
status,
146+
statusText,
147+
mimeType
148+
}) {
149+
return (err, data) => {
150+
// XXX may check data.base64encoded boolean and decode ? Maybe not here...
151+
// if (data.base64encoded) ... Buffer.from(data.body, 'base64');
152+
const errorDetails = {
153+
method,
154+
url,
155+
status,
156+
statusText,
157+
mimeType,
158+
responseBody: data.body
159+
};
160+
mainWindow.webContents.send(
161+
ipcRendererConstants.KEY_IPC_HTTP_ERROR_DATA,
162+
errorDetails
163+
);
164+
};
165+
}
166+
167+
/* Adapted from https://discuss.atom.io/t/electron-intercept-http-request-response-on-browserwindow/21868/7 */
168+
function attachDebugger() {
169+
const debug = mainWindow.webContents.debugger;
170+
debug.attach('1.1');
171+
debug.on('message', (event, method, params) => {
172+
if (
173+
method === 'Network.responseReceived' &&
174+
params.response.status !== 200
175+
) {
176+
const { url, status, statusText, mimeType } = params.response;
177+
debug.sendCommand(
178+
'Network.getResponseBody',
179+
{ requestId: params.requestId },
180+
sendErrorToMainWindow({
181+
url,
182+
status,
183+
statusText,
184+
mimeType,
185+
method: params.response.requestHeadersText.split(' ')[0]
186+
})
187+
);
188+
}
189+
});
190+
debug.sendCommand('Network.enable');
191+
}
192+
140193
mainWindow.on('focus', () => {
141194
const menuBuilder = new MenuBuilder(mainWindow);
142195
menuBuilder.buildMainMenu();
@@ -153,10 +206,6 @@ app.on('ready', async () => {
153206
process.on('uncaughtException', err => {
154207
// log.error(JSON.stringify(err));
155208
});
156-
157-
session.defaultSession.webRequest.onErrorOccurred((details) => {
158-
log.error(JSON.stringify(details));
159-
});
160209
*/
161210
/*
162211
// Remove this if your app does not use auto updates

app/services/dbl_dot_local.service.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ function startEventSource(authToken, getState) {
476476
const eventSource = new EventSource(
477477
`${dblDotLocalConstants.getHttpDblDotLocalBaseUrl()}/events/${authToken}`
478478
);
479-
log.info(`SSE connected: ${authToken}`);
479+
log.info(`SSE connected: ${authToken.substring(0, 16)}...`);
480480
eventSource.onmessage = event => {
481481
log.info(event);
482482
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nathanael",
33
"productName": "nathanael",
4-
"version": "0.47.4",
4+
"version": "0.48.0",
55
"description": "Electron frontend to DBL dot Local",
66
"scripts": {
77
"build": "concurrently \"yarn build-main\" \"yarn build-renderer\"",

0 commit comments

Comments
 (0)