4
4
"bytes"
5
5
"context"
6
6
"encoding/json"
7
- "fmt"
8
7
"net/http"
9
8
10
9
"github.com/Yamashou/gqlgenc/graphqljson"
@@ -43,12 +42,12 @@ func (c *Client) newRequest(ctx context.Context, query string, vars map[string]i
43
42
44
43
requestBody , err := json .Marshal (r )
45
44
if err != nil {
46
- return nil , fmt .Errorf ("encode: %s " , err . Error () )
45
+ return nil , xerrors .Errorf ("encode: %w " , err )
47
46
}
48
47
49
48
req , err := http .NewRequestWithContext (ctx , http .MethodPost , c .BaseURL , bytes .NewBuffer (requestBody ))
50
49
if err != nil {
51
- return nil , xerrors .Errorf (": %w" , err )
50
+ return nil , xerrors .Errorf ("create request struct failed : %w" , err )
52
51
}
53
52
54
53
for _ , httpRequestOption := range c .HTTPRequestOptions {
@@ -66,18 +65,18 @@ func (c *Client) newRequest(ctx context.Context, query string, vars map[string]i
66
65
func (c * Client ) Post (ctx context.Context , query string , respData interface {}, vars map [string ]interface {}, httpRequestOptions ... HTTPRequestOption ) error {
67
66
req , err := c .newRequest (ctx , query , vars , httpRequestOptions )
68
67
if err != nil {
69
- return xerrors .Errorf (": %w" , err )
68
+ return xerrors .Errorf ("don't create request : %w" , err )
70
69
}
71
70
req .Header .Add ("Content-Type" , "application/json" )
72
71
73
72
resp , err := c .Client .Do (req )
74
73
if err != nil {
75
- return xerrors .Errorf (": %w" , err )
74
+ return xerrors .Errorf ("request failed : %w" , err )
76
75
}
77
76
defer resp .Body .Close ()
78
77
79
78
if err := graphqljson .Unmarshal (resp .Body , respData ); err != nil {
80
- return xerrors .Errorf (": %w" , err )
79
+ return xerrors .Errorf ("response mapping failed : %w" , err )
81
80
}
82
81
83
82
if resp .StatusCode < 200 || 299 < resp .StatusCode {
0 commit comments