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

Commit

Permalink
feat(errors): create a util for making error messages more user-friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Aug 25, 2018
1 parent 240a2bc commit da1a53e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/components/GlobalError/GlobalError.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import MdClose from 'react-icons/lib/md/close'
import errorToUserFriendly from 'lib/utils/userFriendlyErrors'
import styles from './GlobalError.scss'

class GlobalError extends React.Component {
Expand All @@ -20,7 +21,7 @@ class GlobalError extends React.Component {
<div className={styles.close} onClick={clearError}>
<MdClose />
</div>
<h2>{error}</h2>
<h2>{errorToUserFriendly(error)}</h2>
</div>
</div>
)
Expand Down
3 changes: 2 additions & 1 deletion app/components/GlobalError/GlobalError.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
max-width: 75%;
margin-left: auto;
margin-right: auto;
font-size: 20px;
font-size: 15px;
line-height: 20px;
letter-spacing: 1.5px;
font-weight: bold;
}
Expand Down
9 changes: 9 additions & 0 deletions app/lib/utils/userFriendlyErrors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const userFriendlyErrors = {
'Error: 11 OUT_OF_RANGE: EOF':
"The person you're trying to connect to isn't available or rejected the connection.\
Their public key may have changed or the server may no longer be responding."
}

const errorToUserFriendly = error => userFriendlyErrors[error] || error

export default errorToUserFriendly
17 changes: 17 additions & 0 deletions test/unit/utils/userFriendlyErrors.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import errorToUserFriendly from 'lib/utils/userFriendlyErrors'

describe('userFriendlyErrors', () => {
describe('errorToUserFriendly', () => {
it('should handle defined user-friendly errors', () => {
expect(errorToUserFriendly('Error: 11 OUT_OF_RANGE: EOF')).toBe(
"The person you're trying to connect to isn't available or rejected the connection.\
Their public key may have changed or the server may no longer be responding."
)
})

it('should return the original error when there is no user-friendly error conversion', () => {
expect(errorToUserFriendly('Error 12')).toBe('Error 12')
expect(errorToUserFriendly('???')).toBe('???')
})
})
})

0 comments on commit da1a53e

Please sign in to comment.