From 154072e217d5a8d6d4d2d7e3be4f1d305a324f84 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 3 Apr 2018 14:11:01 -0700 Subject: [PATCH] Don't swallow logical.Unwrap error (#4258) This PR fixes the error handling in the api packages logical.Unwrap method. Previously if there was an error making the request to Vault, the error was only returned if there was an HTTP response and the status code was not a 404. The new code returns all errors but does special case handling if the response code is a 404. --- api/logical.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/logical.go b/api/logical.go index b19b2746845f..a492b5ab9230 100644 --- a/api/logical.go +++ b/api/logical.go @@ -138,10 +138,11 @@ func (c *Logical) Unwrap(wrappingToken string) (*Secret, error) { if resp != nil { defer resp.Body.Close() } - if err != nil { - if resp != nil && resp.StatusCode != 404 { - return nil, err - } + + // Return all errors except those that are from a 404 as we handle the not + // found error as a special case. + if err != nil && (resp == nil || resp.StatusCode != 404) { + return nil, err } if resp == nil { return nil, nil