Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-cmds
Commits
1adb804f
Unverified
Commit
1adb804f
authored
Jun 13, 2019
by
Steven Allen
Committed by
GitHub
Jun 13, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #170 from ipfs/feat/better-errors
make ErrorType a valid error and implement Unwrap on Error
parents
6069424b
59cf45cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
error.go
error.go
+27
-0
No files found.
error.go
View file @
1adb804f
...
...
@@ -24,6 +24,27 @@ const (
ErrForbidden
)
func
(
e
ErrorType
)
Error
()
string
{
return
e
.
String
()
}
func
(
e
ErrorType
)
String
()
string
{
switch
e
{
case
ErrNormal
:
return
"command failed"
case
ErrClient
:
return
"invalid argument"
case
ErrImplementation
:
return
"internal error"
case
ErrRateLimited
:
return
"rate limited"
case
ErrForbidden
:
return
"request forbidden"
default
:
return
"unknown error code"
}
}
// Error is a struct for marshalling errors
type
Error
struct
{
Message
string
...
...
@@ -42,6 +63,12 @@ func (e Error) Error() string {
return
e
.
Message
}
// Unwrap returns the base error (an ErrorType). Works with go 1.13 error
// helpers.
func
(
e
Error
)
Unwrap
()
error
{
return
e
.
Code
}
func
(
e
Error
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
struct
{
Message
string
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment