Skip to content
This repository has been archived by the owner on Oct 11, 2019. It is now read-only.

Commit

Permalink
Return context.Err() if context is aborted
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasfj committed Apr 10, 2018
1 parent 2965059 commit 80add6c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 4 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ func (client *Client) APICall(payload interface{}, method, route string, result
callSummary, err := client.Request(rawPayload, method, route, query)
callSummary.HTTPRequestObject = payload
if err != nil {
// If context failed during this request, then we should just return that error
if client.Context != nil && client.Context.Err() != nil {
return result, callSummary, client.Context.Err()
}
return result,
callSummary,
&APICallException{
Expand Down
9 changes: 2 additions & 7 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,8 @@ func TestRequestWithContext(t *testing.T) {
if err == nil {
t.Fatal("Should have had a cancel error")
}
switch e := err.(type) {
case *APICallException:
if e.RootCause != context.Canceled {
t.Fatalf("Expected canceled error but got %T %v", e, e)
}
default:
t.Fatalf("Was expecting a *tcclient.APICallException but got %T %v", e, e)
if err != context.Canceled {
t.Fatalf("Expected canceled error but got %T %v", err, err)
}
}

Expand Down

0 comments on commit 80add6c

Please sign in to comment.