From 187be4737e57fda04027433e1b67f7e1982b0c9d Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 25 Apr 2020 19:53:24 -0700 Subject: [PATCH] fix: Log errors to console when Sentry not installed --- app/components/ErrorBoundary.js | 1 + server/app.js | 20 ++++++++++++-------- server/mailer.js | 4 +++- server/utils/s3.js | 4 ++-- server/utils/zip.js | 7 +++---- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/components/ErrorBoundary.js b/app/components/ErrorBoundary.js index 993f58385..c28c5369c 100644 --- a/app/components/ErrorBoundary.js +++ b/app/components/ErrorBoundary.js @@ -20,6 +20,7 @@ class ErrorBoundary extends React.Component { componentDidCatch(error: Error, info: Object) { this.error = error; + console.error(error); if (window.Sentry) { Sentry.captureException(error); diff --git a/server/app.js b/server/app.js index 510ecf922..13ef2ba41 100644 --- a/server/app.js +++ b/server/app.js @@ -94,22 +94,26 @@ if (process.env.SENTRY_DSN) { environment: process.env.NODE_ENV, maxBreadcrumbs: 0, }); +} - app.on('error', (error, ctx) => { - // we don't need to report every time a request stops to the bug tracker - if (error.code === 'EPIPE' || error.code === 'ECONNRESET') { - console.warn('Connection error', { error }); - return; - } +app.on('error', (error, ctx) => { + // we don't need to report every time a request stops to the bug tracker + if (error.code === 'EPIPE' || error.code === 'ECONNRESET') { + console.warn('Connection error', { error }); + return; + } + if (process.env.SENTRY_DSN) { Sentry.withScope(function(scope) { scope.addEventProcessor(function(event) { return Sentry.Handlers.parseRequest(event, ctx.request); }); Sentry.captureException(error); }); - }); -} + } else { + console.error(error); + } +}); app.use(mount('/auth', auth)); app.use(mount('/api', api)); diff --git a/server/mailer.js b/server/mailer.js index 985c85bc8..80d31a303 100644 --- a/server/mailer.js +++ b/server/mailer.js @@ -83,7 +83,9 @@ export class Mailer { attachments: data.attachments, }); } catch (err) { - Sentry.captureException(err); + if (process.env.SENTRY_DSN) { + Sentry.captureException(err); + } throw err; // Re-throw for queue to re-try } } diff --git a/server/utils/s3.js b/server/utils/s3.js index af851cd1f..779033355 100644 --- a/server/utils/s3.js +++ b/server/utils/s3.js @@ -115,7 +115,7 @@ export const uploadToS3FromUrl = async ( const endpoint = publicS3Endpoint(true); return `${endpoint}/${key}`; } catch (err) { - if (process.env.NODE_ENV === 'production') { + if (process.env.SENTRY_DSN) { Sentry.captureException(err); } else { throw err; @@ -157,7 +157,7 @@ export const getImageByKey = async (key: string) => { const data = await s3.getObject(params).promise(); return data.Body; } catch (err) { - if (process.env.NODE_ENV === 'production') { + if (process.env.SENTRY_DSN) { Sentry.captureException(err); } else { throw err; diff --git a/server/utils/zip.js b/server/utils/zip.js index fe98595d6..b2713221c 100644 --- a/server/utils/zip.js +++ b/server/utils/zip.js @@ -34,12 +34,11 @@ async function addImageToArchive(zip, key) { const img = await getImageByKey(key); zip.file(key, img, { createFolders: true }); } catch (err) { - if (process.env.NODE_ENV === 'production') { + if (process.env.SENTRY_DSN) { Sentry.captureException(err); - } else { - // error during file retrieval - console.error(err); } + // error during file retrieval + console.error(err); } }