aboutsummaryrefslogtreecommitdiff
path: root/provider.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-01-19 17:28:13 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-01-19 17:28:13 +0100
commit1263083a2d8dbab56cf06ebf6c74b06dbc989eea (patch)
tree7f46b3a44ce5af71fa466aece036bc01f0fec637 /provider.go
parent9ed605aad5f9a94ee0c050155c02dc31e9652764 (diff)
Move problem handler into RoundTripper
Diffstat (limited to 'provider.go')
-rw-r--r--provider.go25
1 files changed, 7 insertions, 18 deletions
diff --git a/provider.go b/provider.go
index a4aab8a..bba9efc 100644
--- a/provider.go
+++ b/provider.go
@@ -36,6 +36,11 @@ func (p Provider) RoundTrip(req *http.Request) (*http.Response, error) {
if nonce != "" && len(p.nonces) < cap(p.nonces) {
p.nonces <- nonce
}
+ // not sure if it belongs here
+ if hasProblem(resp) {
+ defer resp.Body.Close()
+ return nil, problem(resp.Body)
+ }
return resp, nil
}
@@ -68,27 +73,11 @@ func (p *Provider) post(uri string, s Signer, v interface{}) (*http.Response, er
if err != nil {
return nil, err
}
- resp, err := p.Post(uri, "application/jose+json", signed)
- if err != nil {
- return nil, err
- }
- if hasProblem(resp) {
- defer resp.Body.Close()
- return nil, problem(resp.Body)
- }
- return resp, nil
+ return p.Post(uri, "application/jose+json", signed)
}
func (p *Provider) get(uri string) (*http.Response, error) {
- resp, err := p.Get(uri)
- if err != nil {
- return nil, err
- }
- if hasProblem(resp) {
- defer resp.Body.Close()
- return nil, problem(resp.Body)
- }
- return resp, nil
+ return p.Get(uri)
}
type nextStep struct {