Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commitf014a2e

Browse files
committed
fixup! fixup! Add integration tests for Secrets commands
1 parent6751fa8 commitf014a2e

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
varErrNotFound=xerrors.Errorf("resource not found")
1213

14+
typeapiErrorstruct {
15+
Errstruct {
16+
Msgstring`json:"msg,required"`
17+
}`json:"error"`
18+
}
19+
1320
funcbodyError(resp*http.Response)error {
1421
byt,err:=httputil.DumpResponse(resp,false)
1522
iferr!=nil {
1623
returnxerrors.Errorf("dump response: %w",err)
1724
}
18-
returnxerrors.Errorf("%s\n%s",resp.Request.URL,byt)
25+
26+
varmsgapiError
27+
err=json.NewDecoder(resp.Body).Decode(&msg)
28+
iferr!=nil||msg.Err.Msg=="" {
29+
returnxerrors.Errorf("%s\n%s",resp.Request.URL,byt)
30+
}
31+
returnxerrors.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
deferresp.Body.Close()
4141

42-
ifresp.StatusCode!=200 {
42+
ifresp.StatusCode>299 {
4343
returnbodyError(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(reqInsertSecretReq)error {
62-
_,err:=c.request(http.MethodPost,"/api/users/me/secrets",req)
62+
varrespinterface{}
63+
err:=c.requestBody(http.MethodPost,"/api/users/me/secrets",req,&resp)
6364
returnerr
6465
}
6566

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp