Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
xxdk-wasm
Commits
ab6e7b14
Commit
ab6e7b14
authored
2 years ago
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Implement errors.go
parent
1f920df8
No related branches found
No related tags found
1 merge request
!60
Revert "Fail a test to be sure it works"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.go
+6
-0
6 additions, 0 deletions
main.go
wasm/errors.go
+59
-0
59 additions, 0 deletions
wasm/errors.go
with
65 additions
and
0 deletions
main.go
+
6
−
0
View file @
ab6e7b14
...
...
@@ -82,6 +82,12 @@ func main() {
js
.
Global
()
.
Set
(
"InitializeBackup"
,
js
.
FuncOf
(
wasm
.
InitializeBackup
))
js
.
Global
()
.
Set
(
"ResumeBackup"
,
js
.
FuncOf
(
wasm
.
ResumeBackup
))
// bindings/errors.go
js
.
Global
()
.
Set
(
"CreateUserFriendlyErrorMessage"
,
js
.
FuncOf
(
wasm
.
CreateUserFriendlyErrorMessage
))
js
.
Global
()
.
Set
(
"UpdateCommonErrors"
,
js
.
FuncOf
(
wasm
.
UpdateCommonErrors
))
<-
make
(
chan
bool
)
os
.
Exit
(
0
)
}
This diff is collapsed.
Click to expand it.
wasm/errors.go
0 → 100644
+
59
−
0
View file @
ab6e7b14
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
////////////////////////////////////////////////////////////////////////////////
//go:build js && wasm
package
wasm
import
(
"gitlab.com/elixxir/client/bindings"
"syscall/js"
)
// CreateUserFriendlyErrorMessage will convert the passed in error string to an
// error string that is user-friendly if a substring match is found to a
// common error. Common errors is a map that can be updated using
// UpdateCommonErrors. If the error is not common, some simple parsing is done
// on the error message to make it more user-accessible, removing backend
// specific jargon.
//
// Parameters:
// - args[0] - an error returned from the backend (string).
//
// Returns
// - A user-friendly error message. This should be devoid of technical speak
// but still be meaningful for front-end or back-end teams (string).
func
CreateUserFriendlyErrorMessage
(
_
js
.
Value
,
args
[]
js
.
Value
)
interface
{}
{
return
bindings
.
CreateUserFriendlyErrorMessage
(
args
[
0
]
.
String
())
}
// UpdateCommonErrors updates the internal error mapping database. This internal
// database maps errors returned from the backend to user-friendly error
// messages.
//
// Parameters:
// - args[0] - contents of a JSON file whose format conforms to the example
// below (string).
//
// 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",
// }
//
// Returns:
// - throws a TypeError if the JSON cannot be unmarshalled.
func
UpdateCommonErrors
(
_
js
.
Value
,
args
[]
js
.
Value
)
interface
{}
{
err
:=
bindings
.
UpdateCommonErrors
(
args
[
0
]
.
String
())
if
err
!=
nil
{
Throw
(
TypeError
,
err
.
Error
())
return
nil
}
return
nil
}
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