diff --git a/.eslintrc b/.eslintrc index 0fa74ebc..7be404db 100644 --- a/.eslintrc +++ b/.eslintrc @@ -26,6 +26,7 @@ "jest.framework-setup.js", "cosmos.config.js", "cosmos.test.js", + "next.config.js", "server.js", "server/**/*.js" ], diff --git a/components/Layout.js b/components/Layout.js index dbd9d8ca..72cc3a92 100644 --- a/components/Layout.js +++ b/components/Layout.js @@ -5,6 +5,7 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import Head from 'next/head'; import Error from './pages/Error'; +import { logError } from '../utils/rollbar-client'; import type { Node } from 'react'; import type { State } from '../types/state'; @@ -40,6 +41,8 @@ class Layout extends Component { } componentDidCatch(error, { componentStack }) { + logError(error); + this.setState({ error: { message: error.toString(), diff --git a/next.config.js b/next.config.js new file mode 100644 index 00000000..a51c2ebf --- /dev/null +++ b/next.config.js @@ -0,0 +1,10 @@ +module.exports = { + webpack(cfg) { + // XXX: Uncomment to generate unminified production code + // cfg.plugins = cfg.plugins.filter( + // plugin => plugin.constructor.name !== 'UglifyJsPlugin' + // ); + + return cfg; + } +}; diff --git a/reducers/game.js b/reducers/game.js index 494a0472..ae2c8758 100644 --- a/reducers/game.js +++ b/reducers/game.js @@ -1,5 +1,6 @@ // @flow +import { find } from 'lodash'; import { WELL_ROWS, WELL_COLS, @@ -460,7 +461,7 @@ export function isPlayer(game: Game, curUser: ?User): boolean { } export function getPlayer(game: Game, userId: UserId): Player { - const player = game.players.find(p => p.user.id === userId); + const player = find(game.players, p => p.user.id === userId); if (!player) { throw new Error(`Player with userId ${userId} does not exist`); @@ -481,7 +482,7 @@ export function getCurPlayer(game: Game, curUser: ?User): Player { export function getOtherPlayer(game: Game, curPlayer: Player): ?Player { // NOTE: This only works with max 2 players per game - return game.players.find(p => p !== curPlayer); + return find(game.players, p => p !== curPlayer); } export function allPlayersReady(game: Game) { diff --git a/server/api.js b/server/api.js index aff06331..c2803b8b 100644 --- a/server/api.js +++ b/server/api.js @@ -1,5 +1,6 @@ // @flow +import { find } from 'lodash'; import { users, sessions, @@ -140,7 +141,8 @@ function extractBackfillRequest(req: mixed): BackfillRequest { function getBackfillActions(req: BackfillRequest): BackfillResponse { return gameActions[req.gameId].filter(action => { - const player = req.players.find( + const player = find( + req.players, ({ userId }) => userId === action.payload.userId ); diff --git a/utils/rollbar-client.js b/utils/rollbar-client.js new file mode 100644 index 00000000..8768a1f4 --- /dev/null +++ b/utils/rollbar-client.js @@ -0,0 +1,11 @@ +/* global window */ +// @flow + +export function logError(err: Error) { + try { + window.Rollbar.error(err); + } catch (err2) { + console.error('Rollbar client failed'); + console.error(err2); + } +}