From 277fb6c5b6c93adf989afadff17f09daafefa3dd Mon Sep 17 00:00:00 2001 From: Conrad Date: Tue, 16 May 2017 17:24:41 -0400 Subject: [PATCH 1/2] Add errors to utility scraper --- src/components/Utilities/index.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js index 5fd1dc15..61d088e9 100644 --- a/src/components/Utilities/index.js +++ b/src/components/Utilities/index.js @@ -55,7 +55,9 @@ class Utilities extends Component { }); this.resetErrorMessage(); } else if (res.err) { - this.setState({ error: `Failed to retrieve utility accounts. | ${res.err.message}` }); + res.err.responseBody.then((message) => { + this.setState({ error: `Failed to retrieve utility accounts. | ${message.data}` }); + }); } }); } @@ -78,7 +80,9 @@ class Utilities extends Component { }), }).then((res) => { if (res.err) { - this.setState({ error: `Failed to retrieve utility bill. | ${res.err.message}` }); + res.err.responseBody.then((message) => { + this.setState({ error: `Failed to fetch utility bill. | ${message.data}` }); + }); } else { const data = res.data; setBillData(data.bill_database_output); @@ -113,7 +117,9 @@ class Utilities extends Component { }), }).then((res) => { if (res.err) { - this.setState({ error: `Failed to update utility bill. | ${res.err.message}` }); + res.err.responseBody.then((message) => { + this.setState({ error: `Failed to update utility bill. | ${message.data}` }); + }); } else { const data = res.data; // If we upload disaggregated bill there will be no bill data @@ -155,11 +161,13 @@ class Utilities extends Component { }), }).then((res) => { if (res.err) { - this.setState({ error: `There was an error while creating the account. | ${res.err.message}` }); - const allAccounts = this.state.accountLines.slice(); - allAccounts.pop(); - allAccounts.push(this.createUtilityComponent()); - this.setState({ accountLines: allAccounts }); + res.err.responseBody.then((message) => { + this.setState({ error: `There was an error while creating the account. | ${message.data}` }); + const allAccounts = this.state.accountLines.slice(); + allAccounts.pop(); + allAccounts.push(this.createUtilityComponent()); + this.setState({ accountLines: allAccounts }); + }); } else { /* NOTE: The reason to remove the last item and re-add it is to update the props of that component. If the user decides to delete the newly @@ -199,7 +207,9 @@ class Utilities extends Component { this.setState({ accountLines: newAccounts }); this.resetErrorMessage(); } else { - this.setState({ error: `Failed to delete account. | ${res.err.message}` }); + res.err.responseBody.then((message) => { + this.setState({ error: `Failed to delete account. | ${message.data}` }); + }); } }); } -- GitLab From 491f67e350d24ed1666060ead4eabf4e05fe434a Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 17 May 2017 09:56:36 -0400 Subject: [PATCH 2/2] Use Error Alert component --- src/components/Utilities/index.js | 39 +++++++++++-------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js index 61d088e9..c526b49e 100644 --- a/src/components/Utilities/index.js +++ b/src/components/Utilities/index.js @@ -2,6 +2,7 @@ import React, { Component, PropTypes } from 'react'; import buildingDetailPropTypes from '../../containers/Building/propTypes'; import request from '../../utils/request'; +import ErrorAlert from '../../components/ErrorAlert'; import { getHeaders, scrapeURL, accountURL } from '../../utils/restServices'; import UtilityAccount from '../UtilityAccount'; @@ -55,9 +56,7 @@ class Utilities extends Component { }); this.resetErrorMessage(); } else if (res.err) { - res.err.responseBody.then((message) => { - this.setState({ error: `Failed to retrieve utility accounts. | ${message.data}` }); - }); + this.setState({ error: res.err }); } }); } @@ -80,9 +79,7 @@ class Utilities extends Component { }), }).then((res) => { if (res.err) { - res.err.responseBody.then((message) => { - this.setState({ error: `Failed to fetch utility bill. | ${message.data}` }); - }); + this.setState({ error: res.err }); } else { const data = res.data; setBillData(data.bill_database_output); @@ -117,9 +114,7 @@ class Utilities extends Component { }), }).then((res) => { if (res.err) { - res.err.responseBody.then((message) => { - this.setState({ error: `Failed to update utility bill. | ${message.data}` }); - }); + this.setState({ error: res.err }); } else { const data = res.data; // If we upload disaggregated bill there will be no bill data @@ -161,13 +156,11 @@ class Utilities extends Component { }), }).then((res) => { if (res.err) { - res.err.responseBody.then((message) => { - this.setState({ error: `There was an error while creating the account. | ${message.data}` }); - const allAccounts = this.state.accountLines.slice(); - allAccounts.pop(); - allAccounts.push(this.createUtilityComponent()); - this.setState({ accountLines: allAccounts }); - }); + this.setState({ error: res.err }); + const allAccounts = this.state.accountLines.slice(); + allAccounts.pop(); + allAccounts.push(this.createUtilityComponent()); + this.setState({ accountLines: allAccounts }); } else { /* NOTE: The reason to remove the last item and re-add it is to update the props of that component. If the user decides to delete the newly @@ -207,9 +200,7 @@ class Utilities extends Component { this.setState({ accountLines: newAccounts }); this.resetErrorMessage(); } else { - res.err.responseBody.then((message) => { - this.setState({ error: `Failed to delete account. | ${message.data}` }); - }); + this.setState({ error: res.err }); } }); } @@ -255,12 +246,10 @@ class Utilities extends Component { render() { return (
-
- {this.state.error} -
+ {this.state.accountLines}
); -- GitLab