@@ -101,6 +101,8 @@ func TestDoErr(t *testing.T) {
101
101
io .WriteString (w , `{
102
102
"errors": [{
103
103
"message": "Something went wrong"
104
+ }, {
105
+ "message": "Something else went wrong"
104
106
}]
105
107
}` )
106
108
}))
@@ -114,7 +116,7 @@ func TestDoErr(t *testing.T) {
114
116
var responseData map [string ]interface {}
115
117
err := client .Run (ctx , & Request {q : "query {}" }, & responseData )
116
118
is .True (err != nil )
117
- is .Equal (err .Error (), "graphql: Something went wrong" )
119
+ is .Equal (err .Error (), "graphql: Something went wrong; Something else went wrong " )
118
120
}
119
121
120
122
func TestDoServerErr (t * testing.T ) {
@@ -167,6 +169,49 @@ func TestDoBadRequestErr(t *testing.T) {
167
169
is .Equal (err .Error (), "graphql: miscellaneous message as to why the the request was bad" )
168
170
}
169
171
172
+ func TestDoBadRequestErrDetails (t * testing.T ) {
173
+ is := is .New (t )
174
+ var calls int
175
+ srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
176
+ calls ++
177
+ is .Equal (r .Method , http .MethodPost )
178
+ query := r .FormValue ("query" )
179
+ is .Equal (query , `query {}` )
180
+ w .WriteHeader (http .StatusBadRequest )
181
+ io .WriteString (w , `{
182
+ "errors": [{
183
+ "message": "Name for character with ID 1002 could not be fetched.",
184
+ "locations": [ { "line": 6, "column": 7 } ],
185
+ "path": [ "hero", "heroFriends", 1, "name" ],
186
+ "extensions": {
187
+ "code": "CAN_NOT_FETCH_BY_ID",
188
+ "timestamp": "Fri Feb 9 14:33:09 UTC 2018"
189
+ }
190
+ }]
191
+ }` )
192
+ }))
193
+ defer srv .Close ()
194
+
195
+ ctx := context .Background ()
196
+ client := NewClient (srv .URL , UseMultipartForm ())
197
+
198
+ ctx , cancel := context .WithTimeout (ctx , 1 * time .Second )
199
+ defer cancel ()
200
+ var responseData map [string ]interface {}
201
+ err := client .Run (ctx , & Request {q : "query {}" }, & responseData )
202
+ errs , ok := err .(Errors )
203
+ is .True (ok )
204
+ is .Equal (len (errs ), 1 )
205
+ e := errs [0 ]
206
+ is .Equal (e .Message , "Name for character with ID 1002 could not be fetched." )
207
+ is .Equal (e .Locations , []Location {{Line : 6 , Column : 7 }})
208
+ is .Equal (e .Path , []interface {}{"hero" , "heroFriends" , 1.0 , "name" })
209
+ is .Equal (e .Extensions , map [string ]interface {}{
210
+ "code" : "CAN_NOT_FETCH_BY_ID" ,
211
+ "timestamp" : "Fri Feb 9 14:33:09 UTC 2018" ,
212
+ })
213
+ }
214
+
170
215
func TestDoNoResponse (t * testing.T ) {
171
216
is := is .New (t )
172
217
var calls int
0 commit comments