Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
refactor(error): handle multiple errors in GlobalError
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Jan 6, 2019
1 parent cdfbfe3 commit 99fa15f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions app/components/GlobalError/GlobalError.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Notification } from 'components/UI'

class GlobalError extends React.Component {
static propTypes = {
error: PropTypes.string,
error: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
clearError: PropTypes.func.isRequired
}

Expand All @@ -21,6 +21,20 @@ class GlobalError extends React.Component {
render() {
const { error, clearError } = this.props

let errors = []

if (error) {
if (Array.isArray(error)) {
errors = error
} else if (typeof error === 'string') {
errors.push(error)
} else if (typeof error === 'object') {
Object.keys(error).forEach(key => {
errors.push(`${key}: ${error[key]}`)
})
}
}

return (
<Transition
native
Expand All @@ -34,9 +48,11 @@ class GlobalError extends React.Component {
(springStyles => (
<Box mt="22px" px={3} width={1} css={{ position: 'absolute', 'z-index': '99999' }}>
<animated.div style={springStyles}>
<Notification variant="error" onClick={clearError}>
{errorToUserFriendly(error)}
</Notification>
{errors.map(error => (
<Notification key={error} variant="error" onClick={clearError}>
{errorToUserFriendly(error)}
</Notification>
))}
</animated.div>
</Box>
))
Expand Down

0 comments on commit 99fa15f

Please sign in to comment.