This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(errors): create a util for making error messages more user-friendly
- Loading branch information
Showing
4 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('???') | ||
}) | ||
}) | ||
}) |