Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
12375724
Commit
12375724
authored
2 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Improve documentation for binding/errors.go
parent
c723b457
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!510
Release
,
!308
Expose registration validation sig
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
bindings/errors.go
+30
-16
30 additions, 16 deletions
bindings/errors.go
with
30 additions
and
16 deletions
bindings/errors.go
+
30
−
16
View file @
12375724
...
@@ -40,19 +40,26 @@ var errToUserErr = map[string]string{
...
@@ -40,19 +40,26 @@ var errToUserErr = map[string]string{
// error<Mux is a global lock for the errToUserErr global.
// error<Mux is a global lock for the errToUserErr global.
var
errorMux
sync
.
RWMutex
var
errorMux
sync
.
RWMutex
////// Error codes //////
// Error codes
const
(
const
UnrecognizedCode
=
"UR: "
UnrecognizedCode
=
"UR: "
const
UnrecognizedMessage
=
UnrecognizedCode
+
"Unrecognized error from XX backend, please report"
UnrecognizedMessage
=
UnrecognizedCode
+
"Unrecognized error from XX backend, please report"
)
// ErrorStringToUserFriendlyMessage takes a passed in errStr which will be
// CreateUserFriendlyErrorMessage will convert the passed in error string
// a backend generated error. These may be error specifically written by
// to an error string that is user-friendly if a substring match is
// the backend team or lower level errors gotten from low level dependencies.
// found to a common error. Common errors is a map which can be updated
// This function will parse the error string for common errors provided from
// using UpdateCommonErrors. If the error is not common, some simple parsing
// errToUserErr to provide a more user-friendly error message for the front end.
// is done on the error message to make it more user-accessible, removing
// If the error is not common, some simple parsing is done on the error message
// backend specific jargon.
// to make it more user-accessible, removing backend specific jargon.
//
func
ErrorStringToUserFriendlyMessage
(
errStr
string
)
string
{
// Parameters
// - errStr - an error returned from the backend.
//
// Returns
// - A user-friendly error message. This should be devoid of technical speak
// but still be meaningful for front-end or back-end teams.
func
CreateUserFriendlyErrorMessage
(
errStr
string
)
string
{
errorMux
.
RLock
()
errorMux
.
RLock
()
defer
errorMux
.
RUnlock
()
defer
errorMux
.
RUnlock
()
// Go through common errors
// Go through common errors
...
@@ -90,10 +97,17 @@ func ErrorStringToUserFriendlyMessage(errStr string) string {
...
@@ -90,10 +97,17 @@ func ErrorStringToUserFriendlyMessage(errStr string) string {
return
fmt
.
Sprintf
(
"%s: %v"
,
UnrecognizedCode
,
errStr
)
return
fmt
.
Sprintf
(
"%s: %v"
,
UnrecognizedCode
,
errStr
)
}
}
// UpdateCommonErrors takes the passed in contents of a JSON file and updates the
// UpdateCommonErrors updates the internal error mapping DB. This internal database
// errToUserErr map with the contents of the json file. The JSON's expected format
// maps errors returned from the backend to user-friendly error messages.
// conform with the commented examples provides in errToUserErr above.
//
// NOTE that you should not pass in a file path, but a preloaded JSON file
// Parameters
// - jsonFile - contents of a JSON file whose format conforms to the example below.
// Example Input:
// {
// "Failed to Unmarshal Conversation": "Could not retrieve conversation",
// "Failed to unmarshal SentRequestMap": "Failed to pull up friend requests",
// "cannot create username when network is not health": "Cannot create username, unable to connect to network",
// }
func
UpdateCommonErrors
(
jsonFile
string
)
error
{
func
UpdateCommonErrors
(
jsonFile
string
)
error
{
errorMux
.
Lock
()
errorMux
.
Lock
()
defer
errorMux
.
Unlock
()
defer
errorMux
.
Unlock
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment