Adding ability to send error object to notify() (#2955)

This commit is contained in:
Sonny 2018-05-02 01:10:44 -07:00 committed by CHaBou
parent 4aedb6b9a0
commit 32626bd2ab
6 changed files with 39 additions and 35 deletions

View file

@ -1,7 +1,11 @@
/* global Notification */
/* eslint no-new:0 */
export default function notify(title, body) {
export default function notify(title, body, details = {}) {
//eslint-disable-next-line no-console
console.log(`[Notification] ${title}: ${body}`);
if (details.error) {
//eslint-disable-next-line no-console
console.error(details.error);
}
new Notification(title, {body});
}

View file

@ -137,11 +137,10 @@ const loadModules = () => {
try {
mod = window.require(path);
} catch (err) {
//eslint-disable-next-line no-console
console.error(err.stack);
notify(
'Plugin load error',
`"${pluginName}" failed to load in the renderer process. Check Developer Tools for details.`
`"${pluginName}" failed to load in the renderer process. Check Developer Tools for details.`,
{error: err}
);
return undefined;
}
@ -276,9 +275,9 @@ function getProps(name, props, ...fnArgs) {
try {
ret_ = fn(...fnArgs, props_);
} catch (err) {
//eslint-disable-next-line no-console
console.error(err.stack);
notify('Plugin error', `${fn._pluginName}: Error occurred in \`${name}\`. Check Developer Tools for details.`);
notify('Plugin error', `${fn._pluginName}: Error occurred in \`${name}\`. Check Developer Tools for details.`, {
error: err
});
return;
}
@ -323,11 +322,10 @@ export function connect(stateFn, dispatchFn, c, d = {}) {
try {
ret_ = fn(state, ret);
} catch (err) {
//eslint-disable-next-line no-console
console.error(err.stack);
notify(
'Plugin error',
`${fn._pluginName}: Error occurred in \`map${name}State\`. Check Developer Tools for details.`
`${fn._pluginName}: Error occurred in \`map${name}State\`. Check Developer Tools for details.`,
{error: err}
);
return;
}
@ -349,11 +347,10 @@ export function connect(stateFn, dispatchFn, c, d = {}) {
try {
ret_ = fn(dispatch, ret);
} catch (err) {
//eslint-disable-next-line no-console
console.error(err.stack);
notify(
'Plugin error',
`${fn._pluginName}: Error occurred in \`map${name}Dispatch\`. Check Developer Tools for details.`
`${fn._pluginName}: Error occurred in \`map${name}Dispatch\`. Check Developer Tools for details.`,
{error: err}
);
return;
}
@ -387,9 +384,9 @@ function decorateReducer(name, fn) {
try {
state__ = pluginReducer(state_, action);
} catch (err) {
//eslint-disable-next-line no-console
console.error(err.stack);
notify('Plugin error', `${fn._pluginName}: Error occurred in \`${name}\`. Check Developer Tools for details.`);
notify('Plugin error', `${fn._pluginName}: Error occurred in \`${name}\`. Check Developer Tools for details.`, {
error: err
});
return;
}
@ -436,7 +433,7 @@ function exposeDecorated(Component_) {
try {
this.props.onDecorated(decorated_);
} catch (e) {
notify('Plugin error', `Error occurred. Check Developer Tools for details`);
notify('Plugin error', `Error occurred. Check Developer Tools for details`, {error: e});
}
}
}
@ -462,11 +459,10 @@ function getDecorated(parent, name) {
class__ = fn(class_, {React, PureComponent, Notification, notify});
class__.displayName = `${fn._pluginName}(${name})`;
} catch (err) {
//eslint-disable-next-line no-console
console.error(err.stack);
notify(
'Plugin error',
`${fn._pluginName}: Error occurred in \`${method}\`. Check Developer Tools for details`
`${fn._pluginName}: Error occurred in \`${method}\`. Check Developer Tools for details`,
{error: err}
);
return;
}