Skip to content
Snippets Groups Projects
Commit 12375724 authored by Josh Brooks's avatar Josh Brooks
Browse files

Improve documentation for binding/errors.go

parent c723b457
Branches
Tags
2 merge requests!510Release,!308Expose registration validation sig
...@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment