Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit f014a2e

Browse files
committed
fixup! fixup! Add integration tests for Secrets commands
1 parent 6751fa8 commit f014a2e

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

internal/entclient/error.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package entclient
22

33
import (
4+
"encoding/json"
45
"net/http"
56
"net/http/httputil"
67

@@ -10,10 +11,22 @@ import (
1011
// ErrNotFound describes an error case in which the requested resource could not be found
1112
var ErrNotFound = xerrors.Errorf("resource not found")
1213

14+
type apiError struct {
15+
Err struct {
16+
Msg string `json:"msg,required"`
17+
} `json:"error"`
18+
}
19+
1320
func bodyError(resp *http.Response) error {
1421
byt, err := httputil.DumpResponse(resp, false)
1522
if err != nil {
1623
return xerrors.Errorf("dump response: %w", err)
1724
}
18-
return xerrors.Errorf("%s\n%s", resp.Request.URL, byt)
25+
26+
var msg apiError
27+
err = json.NewDecoder(resp.Body).Decode(&msg)
28+
if err != nil || msg.Err.Msg == "" {
29+
return xerrors.Errorf("%s\n%s", resp.Request.URL, byt)
30+
}
31+
return xerrors.Errorf("%s\n%s%s", resp.Request.URL, byt, msg.Err.Msg)
1932
}

internal/entclient/request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (c Client) requestBody(
3939
}
4040
defer resp.Body.Close()
4141

42-
if resp.StatusCode != 200 {
42+
if resp.StatusCode > 299 {
4343
return bodyError(resp)
4444
}
4545

internal/entclient/secrets.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ type InsertSecretReq struct {
5959

6060
// InsertSecret adds a new secret for the authed user
6161
func (c *Client) InsertSecret(req InsertSecretReq) error {
62-
_, err := c.request(http.MethodPost, "/api/users/me/secrets", req)
62+
var resp interface{}
63+
err := c.requestBody(http.MethodPost, "/api/users/me/secrets", req, &resp)
6364
return err
6465
}
6566

0 commit comments

Comments
 (0)