Browse Source

Merge pull request #677 from gre/sentry-more-cases

Add a logger.critical for raising exception to Sentry
master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
4ad4e3109e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/components/ThrowBlock.js
  2. 16
      src/logger.js
  3. 2
      src/renderer/init.js
  4. 4
      src/sentry/browser.js
  5. 4
      src/sentry/node.js

2
src/components/ThrowBlock.js

@ -17,7 +17,7 @@ class ThrowBlock extends PureComponent<Props, State> {
}
componentDidCatch(error: Error) {
logger.error(error)
logger.critical(error)
this.setState({ error })
}

16
src/logger.js

@ -134,15 +134,31 @@ export default {
console.log(...args)
addLog('log', ...args)
},
warn: (...args: any) => {
console.warn(...args)
addLog('warn', ...args)
},
error: (...args: any) => {
console.error(...args)
addLog('error', ...args)
},
critical: (error: Error) => {
addLog('critical', error)
console.error(error)
try {
if (typeof window !== 'undefined') {
require('sentry/browser').captureException(error)
} else {
require('sentry/node').captureException(error)
}
} catch (e) {
console.warn("Can't send to sentry", error, e)
}
},
exportLogs: (): Array<{ type: string, date: Date, args: Array<any> }> =>
logs.map(({ type, date, args }) => ({
type,

2
src/renderer/init.js

@ -99,6 +99,6 @@ function r(Comp) {
init().catch(e => {
// for now we make the app crash instead of pending forever. later we can render the error OR try to recover, but probably this is unrecoverable cases.
logger.error(e)
logger.critical(e)
r(<AppError error={e} language="en" />)
})

4
src/sentry/browser.js

@ -7,3 +7,7 @@ import install from './install'
export default (shouldSendCallback: () => boolean) => {
install(Raven, shouldSendCallback, user().id)
}
export const captureException = (e: Error) => {
Raven.captureException(e)
}

4
src/sentry/node.js

@ -6,3 +6,7 @@ import install from './install'
export default (shouldSendCallback: () => boolean, userId: string) => {
install(Raven, shouldSendCallback, userId)
}
export const captureException = (e: Error) => {
Raven.captureException(e)
}

Loading…
Cancel
Save