mirror of
https://github.com/frappe/books.git
synced 2024-09-20 03:29:00 +00:00
feat: add code to post errors on report
This commit is contained in:
parent
de22050633
commit
39b56e1d1c
1
.gitignore
vendored
1
.gitignore
vendored
@ -23,3 +23,4 @@ yarn-error.log*
|
|||||||
|
|
||||||
#Electron-builder output
|
#Electron-builder output
|
||||||
/dist_electron
|
/dist_electron
|
||||||
|
err_log_creds.txt
|
@ -15,6 +15,7 @@ import { autoUpdater } from 'electron-updater';
|
|||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib';
|
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib';
|
||||||
|
import { sendError } from './contactMothership';
|
||||||
import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
|
import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
|
||||||
import saveHtmlAsPdf from './saveHtmlAsPdf';
|
import saveHtmlAsPdf from './saveHtmlAsPdf';
|
||||||
|
|
||||||
@ -202,6 +203,10 @@ ipcMain.handle(IPC_ACTIONS.SAVE_DATA, async (event, data, savePath) => {
|
|||||||
return await fs.writeFile(savePath, data, { encoding: 'utf-8' });
|
return await fs.writeFile(savePath, data, { encoding: 'utf-8' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle(IPC_ACTIONS.SEND_ERROR, (event, bodyJson) => {
|
||||||
|
sendError(bodyJson);
|
||||||
|
});
|
||||||
|
|
||||||
/* ------------------------------
|
/* ------------------------------
|
||||||
* Register app lifecycle methods
|
* Register app lifecycle methods
|
||||||
* ------------------------------*/
|
* ------------------------------*/
|
||||||
|
69
src/contactMothership.js
Normal file
69
src/contactMothership.js
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import { app } from 'electron';
|
||||||
|
import fs from 'fs';
|
||||||
|
import http from 'http';
|
||||||
|
import https from 'https';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
function getUrlAndTokenString() {
|
||||||
|
const inProduction = app.isPackaged;
|
||||||
|
const errLogCredsPath = path.join(__dirname, '../err_log_creds.txt');
|
||||||
|
|
||||||
|
let apiKey, apiSecret, url;
|
||||||
|
try {
|
||||||
|
[apiKey, apiSecret, url] = fs
|
||||||
|
.readFileSync(errLogCredsPath, 'utf-8')
|
||||||
|
.split('\n')
|
||||||
|
.filter((f) => f.length);
|
||||||
|
} catch (err) {
|
||||||
|
if (!inProduction) {
|
||||||
|
console.log('error logging failed');
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
!inProduction && console.log(apiKey, apiSecret, url);
|
||||||
|
return { url: encodeURI(url), tokenString: `token ${apiKey}:${apiSecret}` };
|
||||||
|
}
|
||||||
|
|
||||||
|
function post(bodyJson) {
|
||||||
|
const inProduction = app.isPackaged;
|
||||||
|
const { url, tokenString } = getUrlAndTokenString();
|
||||||
|
const isHttps = url.split(':')[0].toLowerCase() === 'https';
|
||||||
|
const headers = {
|
||||||
|
Authorization: tokenString,
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
};
|
||||||
|
|
||||||
|
const req = (isHttps ? https : http).request(
|
||||||
|
url,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
headers,
|
||||||
|
},
|
||||||
|
(res) => {
|
||||||
|
if (inProduction) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`STATUS: ${res.statusCode}`);
|
||||||
|
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
|
||||||
|
|
||||||
|
res.setEncoding('utf8');
|
||||||
|
res.on('data', (chunk) => {
|
||||||
|
console.log(`BODY: ${chunk}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
req.write(bodyJson);
|
||||||
|
req.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sendError(bodyJson) {
|
||||||
|
post(bodyJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nothing nefarious going on here.
|
||||||
|
// Just regular old user mandated error logging.
|
@ -23,9 +23,18 @@ function shouldNotStore(error: Error) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function reportError(errorLogObj: ErrorLog) {
|
async function reportError(errorLogObj: ErrorLog) {
|
||||||
// push errorlog to frappebooks.com
|
if (!errorLogObj.stack) {
|
||||||
console.log(errorLogObj);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
error_name: errorLogObj.name,
|
||||||
|
message: errorLogObj.message,
|
||||||
|
stack: errorLogObj.stack,
|
||||||
|
more: JSON.stringify(errorLogObj.more ?? {}),
|
||||||
|
};
|
||||||
|
ipcRenderer.invoke(IPC_ACTIONS.SEND_ERROR, JSON.stringify(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getToastProps(errorLogObj: ErrorLog) {
|
function getToastProps(errorLogObj: ErrorLog) {
|
||||||
|
@ -19,6 +19,7 @@ export const IPC_ACTIONS = {
|
|||||||
SAVE_HTML_AS_PDF: 'save-html-as-pdf',
|
SAVE_HTML_AS_PDF: 'save-html-as-pdf',
|
||||||
SAVE_DATA: 'save-data',
|
SAVE_DATA: 'save-data',
|
||||||
SHOW_ERROR: 'show-error',
|
SHOW_ERROR: 'show-error',
|
||||||
|
SEND_ERROR: 'send-error',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DB_CONN_FAILURE = {
|
export const DB_CONN_FAILURE = {
|
||||||
|
Loading…
Reference in New Issue
Block a user