From 92a858215ef3d0c79a0b08d0537ddbba1c735626 Mon Sep 17 00:00:00 2001 From: Russell Haering Date: Mon, 7 May 2018 17:07:16 -0700 Subject: [PATCH] Refactor maybeDeflate() --- decode_response.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/decode_response.go b/decode_response.go index 6cc37a4..a40e4b1 100644 --- a/decode_response.go +++ b/decode_response.go @@ -304,16 +304,16 @@ func DecodeUnverifiedBaseResponse(encodedResponse string) (*types.UnverifiedBase // the decoder over the deflated data. func maybeDeflate(data []byte, decoder func([]byte) error) error { err := decoder(data) - if err != nil { - deflated, err := ioutil.ReadAll(flate.NewReader(bytes.NewReader(data))) - if err != nil { - return err - } + if err == nil { + return nil + } - return decoder(deflated) + deflated, err := ioutil.ReadAll(flate.NewReader(bytes.NewReader(data))) + if err != nil { + return err } - return nil + return decoder(deflated) } // parseResponse is a helper function that was refactored out so that the XML parsing behavior can be isolated and unit tested