hashicorp / vault-client-go

HashiCorp Vault Go Client Library generated from OpenAPI spec.
Mozilla Public License 2.0
84 stars 17 forks source link

Fix error parsing for valid JSON responses #247

Closed averche closed 11 months ago

averche commented 11 months ago

Description

When parsing error responses, if the message does not include "errors" or "error" JSON elements, the ResponseError.RawResponseBytes will be populated:

s, err := client.Secrets.KvV2Read(ctx, "my-secret", vault.WithMountPath("secret"))
if err != nil {
    var e *vault.ResponseError
    if errors.As(err, &responseError) {
        log.Printf("response status code: %d", e.StatusCode)
        log.Printf("response body: %s", e.RawResponseBytes)
    } else {
        log.Println(err)
    }
}
assert(s == nil)

Resolves #246

How has this been tested?

Added a unit test.