Unverified Commit 1adb804f authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #170 from ipfs/feat/better-errors

make ErrorType a valid error and implement Unwrap on Error
parents 6069424b 59cf45cd
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment