diff --git a/.env.example b/.env.example index c4ed750..54d06e1 100644 --- a/.env.example +++ b/.env.example @@ -15,10 +15,13 @@ REDIS_HOST= REDIS_PORT= # WHITELIST DOMAINS (separated by commas, no space) WHITELISTED_DOMAINS=http://localhost:3000,http://localhost:3080 +# SENTRY CONFIG +SENTRY_DSN= +REACT_APP_SENTRY_DSN= # AUTH0 CREDENTIALS REACT_APP_AUTH0_DOMAIN=.auth0.com REACT_APP_AUTH0_CLIENT_ID= REACT_APP_AUTH0_CALLBACK_URL=http://localhost:3000/callback REACT_APP_AUTH0_TOKEN_ENDPOINT=https://.auth0.com/oauth/token -REACT_APP_AUTH0_API_ENDPOINT=https://.auth0.com/api/v2/users +REACT_APP_AUTH0_API_ENDPOINT=https://.auth0.com/api/v2/users \ No newline at end of file diff --git a/app.js b/app.js index 80f5eac..d75fc51 100644 --- a/app.js +++ b/app.js @@ -19,7 +19,7 @@ const cors = require('cors'); const Sentry = require('@sentry/node'); -Sentry.init({ dsn: '' }); +Sentry.init({ dsn: `${process.env.SENTRY_DSN}` }); // database setup const mongoose = require('mongoose'); diff --git a/bin/www b/bin/www index 3da6c08..8798eb1 100755 --- a/bin/www +++ b/bin/www @@ -57,15 +57,11 @@ function onError(error) { // handle specific listen errors with friendly messages switch (error.code) { case 'EACCES': - console.error(`${bind} requires elevated privileges`); - throw new Error(`${bind} requires elevated privileges`); + Logger.error(`${bind} requires elevated privileges`); process.exit(1); - break; case 'EADDRINUSE': - console.error(`${bind} is already in use`); - throw new Error(`${bind} is already in use`); + Logger.error(`${bind} is already in use`); process.exit(1); - break; default: throw error; } diff --git a/client/src/Auth/Auth.js b/client/src/Auth/Auth.js index 7200e8e..7a1fe92 100644 --- a/client/src/Auth/Auth.js +++ b/client/src/Auth/Auth.js @@ -2,8 +2,7 @@ import history from '../history'; import auth0 from 'auth0-js'; import { AUTH_CONFIG } from './auth0-config'; import $ from 'jquery' - -const Sentry = require('../Sentry/logger'); +import { sendMessage, sendMessageExtra } from '../Sentry/logger'; /* Auth Class */ @@ -48,7 +47,7 @@ export default class Auth { history.replace('/profile'); } else if (err) { history.replace('/profile'); - console.log(err); + sendMessageExtra('Error in authentication',err.error); alert(`Error: ${err.error}. Check the console for further details.`); } }); @@ -96,7 +95,7 @@ export default class Auth { return new Promise((resolve, reject) => { const accessToken = localStorage.getItem('access_token'); if (!accessToken) { - Sentry.captureMessage('No access token found'); + sendMessage('No access token found'); reject(new Error('No access token found')); } resolve(accessToken); @@ -109,7 +108,7 @@ export default class Auth { return new Promise((resolve, reject) => { const idToken = localStorage.getItem('id_token'); if (!idToken) { - Sentry.captureMessage('No id token found'); + sendMessage('No id token found'); reject(new Error('No id token found')); } resolve(idToken); @@ -132,7 +131,7 @@ export default class Auth { }); }) .catch((err) => { - Sentry.captureMessage('Error while getting profile'); + sendMessageExtra('Error while getting profile',err); return reject(err); }); }); @@ -161,13 +160,13 @@ export default class Auth { return resolve(result); }, error: err => { - Sentry.captureMessage('Error in AJAX call for gettingMetaProfile data'); + sendMessageExtra('Error in AJAX call for getting MetaProfileData',err); return reject(err); } }); }) .catch(err => { - Sentry.captureMessage('Error while getting meta profile data'); + sendMessageExtra('Error while getting meta profile data',err); reject(err); }); }); @@ -197,13 +196,13 @@ export default class Auth { resolve(result); }, error: err => { - Sentry.captureMessage('Error in AJAX call for update data'); + sendMessageExtra('Error in AJAX call for update data',err); reject(err); } }); }) .catch(err => { - Sentry.captureMessage('Error while updating data'); + sendMessageExtra('Error while updating data',err); reject(err); }); }); diff --git a/client/src/Sentry/logger.js b/client/src/Sentry/logger.js index 3429df2..1f71725 100644 --- a/client/src/Sentry/logger.js +++ b/client/src/Sentry/logger.js @@ -1,5 +1,21 @@ const Sentry = require('@sentry/browser'); -Sentry.init({dsn: ""}); +Sentry.init({dsn: `${process.env.REACT_APP_SENTRY_DSN}` }); -module.exports = Sentry; +const sendMessage = ( msg ) => { + Sentry.captureMessage(msg); +} + +const sendMessageExtra = ( msg, obj ) => { + Sentry.captureMessage(msg, {extra: obj}); +} + +const setUserName = ( name ) => { + Sentry.setUser({ username: name }) +} + +module.exports = { + sendMessage, + setUserName, + sendMessageExtra +}; diff --git a/client/src/components/Profile/Profile.js b/client/src/components/Profile/Profile.js index cdbeba4..9899c29 100644 --- a/client/src/components/Profile/Profile.js +++ b/client/src/components/Profile/Profile.js @@ -4,8 +4,7 @@ import ProfilePicture from './ProfilePicture'; import ProfileSettings from './ProfileSettings'; import Sidebar from './Sidebar'; import DailyEmission from './DailyEmission'; - -const Sentry = require('../../Sentry/logger') +import { setUserName } from '../../Sentry/logger' /* Extended react.Component class as Profile */ @@ -46,7 +45,7 @@ export default class Profile extends Component { given_name: profile.given_name, family_name: profile.family_name }); - Sentry.setUser({username: profile.nickname}); + setUserName(profile.nickname); }) .catch(err => { console.log(err); diff --git a/client/src/index.js b/client/src/index.js index 3a23386..bb8ed84 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -1,12 +1,11 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import * as Sentry from '@sentry/browser'; import 'semantic-ui-css/semantic.min.css' import App from './App'; import * as serviceWorker from './serviceWorker'; -Sentry.init({dsn: ""}); +import './Sentry/logger'; ReactDOM.render(, document.getElementById('root')); diff --git a/framework/Logger.js b/framework/Logger.js index f5c5348..881b925 100644 --- a/framework/Logger.js +++ b/framework/Logger.js @@ -13,7 +13,7 @@ const Logger = new winston.Logger({ new winston.transports.File({ level: 'debug', filename: 'dev.log' }), new Sentry({ level: 'error', - dsn: '' + dsn: `${process.env.SENTRY_DSN}` }) ], }); diff --git a/framework/redis.js b/framework/redis.js index c5548c8..47bf329 100644 --- a/framework/redis.js +++ b/framework/redis.js @@ -16,7 +16,6 @@ redisClient // if the connection throws an error .on('error', (err) => { Logger.error(`Redis connection failed: ${err}`); - throw new Error(`Redis connection failed: ${err}`); }) // if the connection is connected .on('connect', () => Logger.info('Redis connected successfully'));