From 5bf9d0f0720f014baff0fe1f4267d91ce7b9b23d Mon Sep 17 00:00:00 2001 From: Hannu Lyytikainen Date: Wed, 27 Sep 2017 10:48:52 +0300 Subject: [PATCH] Send errors to sentry --- server/index.js | 2 +- src/Routes.js | 4 ++-- src/components/BookingBreakdown/BookingBreakdown.js | 12 ++++++++---- .../CurrencyInputField/CurrencyInputField.js | 5 ++--- src/components/ImageFromFile/ImageFromFile.js | 7 ++++--- src/containers/SearchPage/SearchPage.js | 4 ++++ src/index.js | 7 ++++--- 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/server/index.js b/server/index.js index 9d4d6b2b..14a5d983 100644 --- a/server/index.js +++ b/server/index.js @@ -156,7 +156,7 @@ app.get('*', (req, res) => { } }) .catch(e => { - console.error(e); + log.error(e); res.status(500).send(errorPage); }); }); diff --git a/src/Routes.js b/src/Routes.js index 5f691ac7..ac59f590 100644 --- a/src/Routes.js +++ b/src/Routes.js @@ -6,6 +6,7 @@ import { NotFoundPage } from './containers'; import { NamedRedirect } from './components'; import { withFlattenedRoutes } from './util/contextHelpers'; import * as propTypes from './util/propTypes'; +import { error as logError } from './util/log'; const { bool, arrayOf, object, func, shape, string, any } = PropTypes; @@ -29,8 +30,7 @@ const callLoadData = props => { console.log(`loadData success for ${name} route`); }) .catch(e => { - // eslint-disable-next-line no-console - console.error(`loadData error for ${name} route`, e); + logError(e, { route: route }); }); } }; diff --git a/src/components/BookingBreakdown/BookingBreakdown.js b/src/components/BookingBreakdown/BookingBreakdown.js index 55a0b568..8e6675d1 100644 --- a/src/components/BookingBreakdown/BookingBreakdown.js +++ b/src/components/BookingBreakdown/BookingBreakdown.js @@ -8,7 +8,7 @@ import classNames from 'classnames'; import { types } from '../../util/sdkLoader'; import { formatMoney } from '../../util/currency'; import * as propTypes from '../../util/propTypes'; -import * as log from '../../util/log'; +import { error as logError } from '../../util/log'; import css from './BookingBreakdown.css'; @@ -78,10 +78,14 @@ export const BookingBreakdownComponent = props => { if (isProvider) { if (!isValidCommission(providerCommissionLineItem)) { - log.error( - new Error('Commission should be present and the value should be zero or negative'), - { providerCommissionLineItem: providerCommissionLineItem, transaction: transaction } + const error = new Error( + 'Commission should be present and the value should be zero or negative' ); + logError(error, { + providerCommissionLineItem: providerCommissionLineItem, + transaction: transaction, + }); + throw error; } // The total sum that the customer pays is the payinTotal. We use diff --git a/src/components/CurrencyInputField/CurrencyInputField.js b/src/components/CurrencyInputField/CurrencyInputField.js index c2ca5108..41ebeb1a 100644 --- a/src/components/CurrencyInputField/CurrencyInputField.js +++ b/src/components/CurrencyInputField/CurrencyInputField.js @@ -20,6 +20,7 @@ import { truncateToSubUnitPrecision, } from '../../util/currency'; import * as propTypes from '../../util/propTypes'; +import { error as logError } from '../../util/log'; import css from './CurrencyInputField.css'; @@ -81,9 +82,7 @@ class CurrencyInputComponent extends Component { usesComma, }; } catch (e) { - // Print error, if default value isn't supported (see specs: truncateToSubUnitPrecision). - // eslint-disable-next-line no-console - console.error('CurrencyInput:', e); + logError(e, { props: props }); throw e; } diff --git a/src/components/ImageFromFile/ImageFromFile.js b/src/components/ImageFromFile/ImageFromFile.js index 101cdc7f..ecbf6208 100644 --- a/src/components/ImageFromFile/ImageFromFile.js +++ b/src/components/ImageFromFile/ImageFromFile.js @@ -2,6 +2,7 @@ import React, { Component, PropTypes } from 'react'; import { FormattedMessage } from 'react-intl'; import classNames from 'classnames'; import { Promised } from '../../components'; +import { error as logError } from '../../util/log'; import css from './ImageFromFile.css'; @@ -12,9 +13,9 @@ const readImage = file => const reader = new FileReader(); reader.onload = e => resolve(e.target.result); reader.onerror = e => { - // eslint-disable-next-line - console.error('Error (', e, `) happened while reading ${file.name}: ${e.target.result}`); - reject(new Error(`Error reading ${file.name}: ${e.target.result}`)); + const error = new Error(`Error reading ${file.name}: ${e.target.result}`); + logError(error, { file: file }); + reject(error); }; reader.readAsDataURL(file); }); diff --git a/src/containers/SearchPage/SearchPage.js b/src/containers/SearchPage/SearchPage.js index 798f2207..3367f2c8 100644 --- a/src/containers/SearchPage/SearchPage.js +++ b/src/containers/SearchPage/SearchPage.js @@ -11,6 +11,7 @@ import { googleLatLngToSDKLatLng, googleBoundsToSDKBounds } from '../../util/goo import { createResourceLocatorString } from '../../util/routes'; import { createSlug, parse, stringify } from '../../util/urlHelpers'; import * as propTypes from '../../util/propTypes'; +import { error as logError } from '../../util/log'; import { getListingsById } from '../../ducks/marketplaceData.duck'; import { sendVerificationEmail } from '../../ducks/user.duck'; import { logout, authenticationInProgress } from '../../ducks/Auth.duck'; @@ -124,8 +125,11 @@ export class SearchPageComponent extends Component { }) .catch(error => { // In case of error, stop recursive loop and report error. + // TODO: Show a flash message // eslint-disable-next-line no-console console.error(`An error (${error} occured while trying to retrieve map listings`); + + logError(new Error(error)); }); } diff --git a/src/index.js b/src/index.js index 8f0ec527..d3695e1f 100644 --- a/src/index.js +++ b/src/index.js @@ -41,7 +41,7 @@ const render = store => { ReactDOM.render(, document.getElementById('root')); }) .catch(e => { - console.error(e); // eslint-disable-line + log.error(e); }); }; @@ -55,6 +55,9 @@ const setupStripe = () => { // If we're in a browser already, render the client application. if (typeof window !== 'undefined') { + // set up logger with Sentry DSN client key and environment + log.setup(config.sentryDsn, config.env); + // eslint-disable-next-line no-underscore-dangle const preloadedState = window.__PRELOADED_STATE__ || '{}'; const initialState = JSON.parse(preloadedState, types.reviver); @@ -74,8 +77,6 @@ if (typeof window !== 'undefined') { setupStripe(); render(store); - // set up logger with Sentry DSN client key and environment - log.setup(config.sentryDsn, config.env); if (config.dev) { // Expose stuff for the browser REPL