Skip to content

Commit 1f1c5e7

Browse files
committed
fix #56, about missing error check.
1 parent 77ebfd8 commit 1f1c5e7

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

client.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import (
1111
"strconv"
1212
"strings"
1313

14+
"bytes"
15+
"io"
16+
"mime/multipart"
17+
"os"
18+
1419
"golang.org/x/net/context"
1520
"golang.org/x/oauth2"
1621
"golang.org/x/oauth2/bitbucket"
1722
"golang.org/x/oauth2/clientcredentials"
18-
"bytes"
19-
"mime/multipart"
20-
"io"
21-
"os"
2223
)
2324

2425
const DEFAULT_PAGE_LENGTH = 10
@@ -31,7 +32,7 @@ type Client struct {
3132
Repositories *Repositories
3233
Pagelen uint64
3334

34-
HttpClient *http.Client
35+
HttpClient *http.Client
3536
}
3637

3738
type auth struct {
@@ -130,7 +131,7 @@ func injectClient(a *auth) *Client {
130131
Diff: &Diff{c: c},
131132
BranchRestrictions: &BranchRestrictions{c: c},
132133
Webhooks: &Webhooks{c: c},
133-
Downloads: &Downloads{c: c},
134+
Downloads: &Downloads{c: c},
134135
}
135136
c.Users = &Users{c: c}
136137
c.User = &User{c: c}
@@ -167,6 +168,9 @@ func (c *Client) execute(method string, urlStr string, text string) (interface{}
167168

168169
c.authenticateRequest(req)
169170
result, err := c.doRequest(req, false)
171+
if err != nil {
172+
return nil, err
173+
}
170174

171175
//autopaginate.
172176
resultMap, isMap := result.(map[string]interface{})
@@ -221,7 +225,7 @@ func (c *Client) executeFileUpload(method string, urlStr string, filePath string
221225

222226
var fw io.Writer
223227
if fw, err = w.CreateFormFile("files", fileName); err != nil {
224-
return nil , err
228+
return nil, err
225229
}
226230

227231
if _, err = io.Copy(fw, fileReader); err != nil {
@@ -245,7 +249,7 @@ func (c *Client) executeFileUpload(method string, urlStr string, filePath string
245249

246250
}
247251

248-
func (c *Client) authenticateRequest(req *http.Request){
252+
func (c *Client) authenticateRequest(req *http.Request) {
249253
if c.Auth.bearerToken != "" {
250254
req.Header.Set("Authorization", "Bearer "+c.Auth.bearerToken)
251255
}
@@ -258,8 +262,7 @@ func (c *Client) authenticateRequest(req *http.Request){
258262
return
259263
}
260264

261-
262-
func (c *Client) doRequest(req *http.Request, emptyResponse bool) (interface{}, error){
265+
func (c *Client) doRequest(req *http.Request, emptyResponse bool) (interface{}, error) {
263266

264267
resp, err := c.HttpClient.Do(req)
265268
if err != nil {
@@ -295,7 +298,6 @@ func (c *Client) doRequest(req *http.Request, emptyResponse bool) (interface{},
295298
return result, nil
296299
}
297300

298-
299301
func (c *Client) requestUrl(template string, args ...interface{}) string {
300302

301303
if len(args) == 1 && args[0] == "" {

0 commit comments

Comments
 (0)