2
0
mirror of https://github.com/frappe/books.git synced 2025-01-11 10:38:14 +00:00

feat: redirect to create an issue on Report Error

This commit is contained in:
18alantom 2022-01-24 16:49:34 +05:30 committed by Alan
parent b5582ca1da
commit ad496ab80e

View File

@ -7,14 +7,14 @@ import {
ValidationError, ValidationError,
} from 'frappe/common/errors'; } from 'frappe/common/errors';
import BaseDocument from 'frappe/model/document'; import BaseDocument from 'frappe/model/document';
import { IPC_ACTIONS } from './messages'; import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
import { showMessageDialog, showToast } from './utils'; import { showMessageDialog, showToast } from './utils';
interface ErrorLog { interface ErrorLog {
name: string; name: string;
message: string; message: string;
stack?: string; stack?: string;
more?: Object; more?: object;
} }
function shouldNotStore(error: Error) { function shouldNotStore(error: Error) {
@ -40,6 +40,7 @@ function getToastProps(errorLogObj: ErrorLog) {
actionText: t`Report Error`, actionText: t`Report Error`,
action: () => { action: () => {
reportError(errorLogObj); reportError(errorLogObj);
createIssue(errorLogObj);
}, },
}); });
} }
@ -135,3 +136,34 @@ export function getErrorHandledSync(func: Function) {
} }
}; };
} }
function getIssueUrlQuery(errorLogObj: ErrorLog): string {
const baseUrl = 'https://github.com/frappe/books/issues/new?labels=bug';
const body = [
'<h2>Description</h2>',
'Add some description...',
'',
'<h2>Error Info</h2>',
'',
`**Error**: _${errorLogObj.name}: ${errorLogObj.message}_`,
'',
];
if (errorLogObj.stack) {
body.push('**Stack**:', '```', errorLogObj.stack, '```', '');
}
const { fullPath } = errorLogObj.more as { fullPath?: string };
if (fullPath) {
body.push(`**Path**: \`${fullPath}\``);
}
const url = [baseUrl, `body=${body.join('\n')}`].join('&');
return encodeURI(url);
}
function createIssue(errorLogObj: ErrorLog) {
const urlQuery = getIssueUrlQuery(errorLogObj);
ipcRenderer.send(IPC_MESSAGES.OPEN_EXTERNAL, urlQuery);
}