Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #300 from cfpb/handle-fetch-errors
Browse files Browse the repository at this point in the history
handle errors for fetchMsas
  • Loading branch information
wpears authored Jul 15, 2019
2 parents ee46597 + ce37184 commit 1587398
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/reports/Disclosure.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Object.keys(DISCLOSURE_REPORTS).forEach(key =>
class Disclosure extends React.Component {
constructor(props) {
super(props)
this.state = { fetched: false }
this.state = { fetched: false, error: null }
this.makeListItem = this.makeListItem.bind(this)
}

Expand All @@ -56,6 +56,8 @@ class Disclosure extends React.Component {
const msaMds = [...result.msaMds, { id: 'nationwide' }]
fetchedMsas = msaMds
this.setState({ fetched: true })
}).catch(e => {
this.setState({fetched: true, error: `${e.status}: ${e.statusText}`})
})
} else {
this.setState({ fetched: true })
Expand Down Expand Up @@ -116,6 +118,15 @@ class Disclosure extends React.Component {
/>
)

if(this.state.error) {
return (
<div className="Disclosure" id="main-content">
{header}
<p>{this.state.error}</p>
</div>
)
}

return this.state.fetched ? (
<React.Fragment>
<div className="Disclosure" id="main-content">
Expand Down
4 changes: 2 additions & 2 deletions src/reports/MsaMds.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ class MsaMds extends React.Component {
error => {
this.setState({
isLoaded: true,
error
error: `${error.status}: ${error.statusText}`
})
}
)
}
}

render() {
if (!this.state.isLoaded) return <LoadingIcon />
if (this.state.error) return <p>{this.state.error}</p>
if (!this.state.isLoaded) return <LoadingIcon />

const options = this.state.msaMds.map(val => {
let label = val.id
Expand Down
5 changes: 4 additions & 1 deletion src/reports/fetchMsas.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ function getMsaUrl(institutionId, year) {
}

export default function(institutionId, year) {
return fetch(getMsaUrl(institutionId, year)).then(res => res.json())
return fetch(getMsaUrl(institutionId, year)).then(res => {
if(res.status > 399) throw res
return res.json()
})
}

0 comments on commit 1587398

Please sign in to comment.