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
6069424b
Unverified
Commit
6069424b
authored
Jun 11, 2019
by
Steven Allen
Committed by
GitHub
Jun 11, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #168 from ipfs/feat/error-codes
feat: improve error codes
parents
260a5160
d9d26d6e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
7 deletions
+21
-7
error.go
error.go
+11
-6
http/parse.go
http/parse.go
+10
-1
No files found.
error.go
View file @
6069424b
...
...
@@ -11,12 +11,17 @@ type ErrorType uint
// ErrorTypes convey what category of error ocurred
const
(
ErrNormal
ErrorType
=
iota
// general errors
ErrClient
// error was caused by the client, (e.g. invalid CLI usage)
ErrImplementation
// programmer error in the server
ErrNotFound
// == HTTP 404
ErrFatal
// abort instantly
// TODO: add more types of errors for better error-specific handling
// ErrNormal is a normal error. The command failed for some reason that's not a bug.
ErrNormal
ErrorType
=
iota
// ErrClient means the client made an invalid request.
ErrClient
// ErrImplementation means there's a bug in the implementation.
ErrImplementation
// ErrRateLimited is returned when the operation has been rate-limited.
ErrRateLimited
// ErrForbidden is returned when the client doesn't have permission to
// perform the requested operation.
ErrForbidden
)
// Error is a struct for marshalling errors
...
...
http/parse.go
View file @
6069424b
...
...
@@ -216,7 +216,16 @@ func parseResponse(httpRes *http.Response, req *cmds.Request) (cmds.Response, er
return
nil
,
err
}
e
.
Message
=
string
(
mes
)
e
.
Code
=
cmds
.
ErrNormal
switch
httpRes
.
StatusCode
{
case
http
.
StatusNotFound
,
http
.
StatusBadRequest
:
e
.
Code
=
cmds
.
ErrClient
case
http
.
StatusTooManyRequests
:
e
.
Code
=
cmds
.
ErrRateLimited
case
http
.
StatusForbidden
:
e
.
Code
=
cmds
.
ErrForbidden
default
:
e
.
Code
=
cmds
.
ErrNormal
}
case
res
.
dec
==
nil
:
return
nil
,
fmt
.
Errorf
(
"unknown error content type: %s"
,
contentType
)
default
:
...
...
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