From 848d33c195c88b5031fc007405330a7aed78da01 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Mon, 2 Jan 2017 15:39:34 +0200 Subject: [PATCH] #248: Properly handle password confirm in profile form. Fixes sentry/#36 --- src/index.js | 2 +- src/pages/profile/ProfilePage.jsx | 17 +++++++++++++---- src/services/logger.js | 8 +++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index b5059eb..5d96a88 100644 --- a/src/index.js +++ b/src/index.js @@ -76,7 +76,7 @@ function restoreScroll() { const viewPort = document.body; if (!viewPort) { - console.log('Can not find viewPort element'); + console.log('Can not find viewPort element'); // eslint-disable-line return; } diff --git a/src/pages/profile/ProfilePage.jsx b/src/pages/profile/ProfilePage.jsx index 91dbc87..8748a50 100644 --- a/src/pages/profile/ProfilePage.jsx +++ b/src/pages/profile/ProfilePage.jsx @@ -1,5 +1,7 @@ import React, { Component, PropTypes } from 'react'; +import logger from 'services/logger'; + import { FooterMenu } from 'components/footerMenu'; import styles from './profile.scss'; @@ -79,6 +81,13 @@ export default connect(null, { } }) .then((resp) => !resp.requirePassword || requestPassword(form)) + .catch((resp) => { + if (!resp || !resp.errors) { + logger.warn('Unexpected profile editing error', { + resp + }); + } + }) .finally(() => form.endLoading()); function requestPassword(form) { @@ -88,15 +97,15 @@ export default connect(null, { const onSubmit = () => { form.beginLoading(); sendData() + .then(resolve) + .then(props.onClose) .catch((resp) => { if (resp.errors) { form.setErrors(resp.errors); + } else { + return Promise.reject(resp); } - - return Promise.reject(resp); }) - .then(resolve) - .then(props.onClose) .finally(() => form.endLoading()); }; diff --git a/src/services/logger.js b/src/services/logger.js index 9def95f..bbf4aba 100644 --- a/src/services/logger.js +++ b/src/services/logger.js @@ -23,7 +23,13 @@ const logger = { window.addEventListener('unhandledrejection', (event) => { const error = event.reason || {}; - const message = error.message ? `: ${error.message}` : ''; + + let message = error.message || error; + if (typeof message === 'string') { + message = `: ${message}`; + } else { + message = ''; + } logger.info(`Unhandled rejection${message}`, { error