Skip to content

Commit

Permalink
Don't swallow logical.Unwrap error (#4258)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dadgar authored and jefferai committed Apr 3, 2018
1 parent 3b7f197 commit 154072e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions api/logical.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 154072e

Please sign in to comment.