mirror of
https://github.com/frappe/books.git
synced 2024-12-22 10:58:59 +00:00
feat: add code to post errors on report
This commit is contained in:
parent
de22050633
commit
39b56e1d1c
3
.gitignore
vendored
3
.gitignore
vendored
@ -22,4 +22,5 @@ yarn-error.log*
|
||||
*.sw?
|
||||
|
||||
#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 path from 'path';
|
||||
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib';
|
||||
import { sendError } from './contactMothership';
|
||||
import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
|
||||
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' });
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC_ACTIONS.SEND_ERROR, (event, bodyJson) => {
|
||||
sendError(bodyJson);
|
||||
});
|
||||
|
||||
/* ------------------------------
|
||||
* 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) {
|
||||
// push errorlog to frappebooks.com
|
||||
console.log(errorLogObj);
|
||||
async function reportError(errorLogObj: ErrorLog) {
|
||||
if (!errorLogObj.stack) {
|
||||
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) {
|
||||
|
@ -19,6 +19,7 @@ export const IPC_ACTIONS = {
|
||||
SAVE_HTML_AS_PDF: 'save-html-as-pdf',
|
||||
SAVE_DATA: 'save-data',
|
||||
SHOW_ERROR: 'show-error',
|
||||
SEND_ERROR: 'send-error',
|
||||
};
|
||||
|
||||
export const DB_CONN_FAILURE = {
|
||||
|
Loading…
Reference in New Issue
Block a user