From 1263083a2d8dbab56cf06ebf6c74b06dbc989eea Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 19 Jan 2016 17:28:13 +0100 Subject: Move problem handler into RoundTripper --- provider.go | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'provider.go') 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 { -- cgit v1.2.3