-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add context support, ErrUnauthorized and Doer interface for http.Client #4
Changes from 1 commit
6b4902a
9a6f5cb
d3f78fd
6db1851
e210494
549df79
98380c1
12d49ff
4ad4491
5a94976
67b650e
84ac3b0
84152d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"io" | ||
"net/http" | ||
"net/url" | ||
"strings" | ||
"time" | ||
|
||
"github.com/google/go-querystring/query" | ||
|
@@ -124,13 +125,15 @@ type ( | |
|
||
Response struct { | ||
Data interface{} `json:"data,omitempty"` | ||
Errors []Error `json:"errors,omitempty"` | ||
Errors Errors `json:"errors,omitempty"` | ||
} | ||
|
||
Error struct { | ||
Phrase string `json:"phrase,omitempty"` | ||
Message string `json:"message,omitempty"` | ||
} | ||
|
||
Errors []Error | ||
) | ||
|
||
func (f DoerFunc) Do(req *http.Request) (resp *http.Response, err error) { | ||
|
@@ -141,6 +144,14 @@ func (e Error) Error() string { | |
return fmt.Sprintf("%v - %v", e.Message, e.Phrase) | ||
} | ||
|
||
func (e Errors) Error() string { | ||
var sErrs []string | ||
for _, err := range e { | ||
sErrs = append(sErrs, err.Error()) | ||
} | ||
return strings.Join(sErrs, ", ") | ||
} | ||
|
||
//NewClient created new asana client with doer. | ||
//If doer is nil then http.DefaultClient used intead. | ||
func NewClient(doer Doer) *Client { | ||
|
@@ -272,7 +283,7 @@ func (c *Client) request(method string, path string, data interface{}, opt *Filt | |
res := &Response{Data: v} | ||
err = json.NewDecoder(resp.Body).Decode(res) | ||
if len(res.Errors) > 0 { | ||
return res.Errors[0] | ||
return res.Errors | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to this, at least 1 element. I think it's worth documenting that for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are correct, add godoc for Errors type |
||
} | ||
return err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any restrictions on
Errors
? Can it contain 0 elements? 1 element?