From 55586b9b2a2a787a2c0968ab9fa55d295b8d2d26 Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Wed, 31 Oct 2018 12:04:33 -0400 Subject: [PATCH] convert post-api.login code to using async/await for Login.jsx --- src/pages/Login.jsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/pages/Login.jsx b/src/pages/Login.jsx index 37f5ece0df..c806ef24b4 100644 --- a/src/pages/Login.jsx +++ b/src/pages/Login.jsx @@ -41,7 +41,7 @@ class LoginPage extends Component { handlePasswordChange = value => this.safeSetState({ password: value, error: '' }); - handleSubmit = event => { + handleSubmit = async event => { const { username, password, loading } = this.state; event.preventDefault(); @@ -49,15 +49,15 @@ class LoginPage extends Component { if (!loading) { this.safeSetState({ loading: true }); - api.login(username, password) - .catch(error => { - if (error.response.status === 401) { - this.safeSetState({ error: LOGIN_ERROR_MESSAGE }); - } - }) - .finally(() => { - this.safeSetState({ loading: false }); - }); + try { + await api.login(username, password); + } catch (error) { + if (error.response.status === 401) { + this.safeSetState({ error: LOGIN_ERROR_MESSAGE }); + } + } finally { + this.safeSetState({ loading: false }); + } } }