Browse Source

feat(errors): create a util for making error messages more user-friendly

renovate/lint-staged-8.x
Evan Kaloudis 6 years ago
parent
commit
da1a53ecc8
  1. 3
      app/components/GlobalError/GlobalError.js
  2. 3
      app/components/GlobalError/GlobalError.scss
  3. 9
      app/lib/utils/userFriendlyErrors.js
  4. 17
      test/unit/utils/userFriendlyErrors.spec.js

3
app/components/GlobalError/GlobalError.js

@ -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 {
@ -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>
)

3
app/components/GlobalError/GlobalError.scss

@ -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;
}

9
app/lib/utils/userFriendlyErrors.js

@ -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
test/unit/utils/userFriendlyErrors.spec.js

@ -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('???')
})
})
})
Loading…
Cancel
Save