@@ -2,7 +2,6 @@ package handler_test
2
2
3
3
import (
4
4
"encoding/json"
5
- "errors"
6
5
"fmt"
7
6
"io/ioutil"
8
7
"net/http"
@@ -215,15 +214,15 @@ func TestHandler_BasicQuery_WithRootObjFn(t *testing.T) {
215
214
}
216
215
217
216
type customError struct {
218
- error
217
+ message string
219
218
}
220
219
221
220
func (e customError ) Error () string {
222
- return e . error . Error ( )
221
+ return fmt . Sprintf ( "%s" , e . message )
223
222
}
224
223
225
224
func TestHandler_BasicQuery_WithFormatErrorFn (t * testing.T ) {
226
- resolverError := customError {error : errors . New ( "resolver error" ) }
225
+ resolverError := customError {message : "resolver error" }
227
226
myNameQuery := graphql .NewObject (graphql.ObjectConfig {
228
227
Name : "Query" ,
229
228
Fields : graphql.Fields {
@@ -252,9 +251,6 @@ func TestHandler_BasicQuery_WithFormatErrorFn(t *testing.T) {
252
251
},
253
252
},
254
253
Path : []interface {}{"name" },
255
- Extensions : map [string ]interface {}{
256
- "fromFormatFn" : "FROM_FORMAT_FN" ,
257
- },
258
254
}
259
255
260
256
expected := & graphql.Result {
@@ -271,22 +267,16 @@ func TestHandler_BasicQuery_WithFormatErrorFn(t *testing.T) {
271
267
h := handler .New (& handler.Config {
272
268
Schema : & myNameSchema ,
273
269
Pretty : true ,
274
- FormatErrorFn : func (err gqlerrors. FormattedError ) gqlerrors.FormattedError {
270
+ FormatErrorFn : func (err error ) gqlerrors.FormattedError {
275
271
formatErrorFnCalled = true
276
- originalError := err .OriginalError ()
277
- switch errType := originalError .(type ) {
278
- case customError :
272
+ var formatted gqlerrors.FormattedError
273
+ switch err := err .(type ) {
274
+ case * gqlerrors.Error :
275
+ formatted = gqlerrors .FormatError (err )
279
276
default :
280
- t .Fatalf ("unexpected error type: %v" , reflect .TypeOf (errType ))
281
- }
282
- return gqlerrors.FormattedError {
283
- Message : err .Message ,
284
- Locations : err .Locations ,
285
- Path : err .Path ,
286
- Extensions : map [string ]interface {}{
287
- "fromFormatFn" : "FROM_FORMAT_FN" ,
288
- },
277
+ t .Fatalf ("unexpected error type: %v" , reflect .TypeOf (err ))
289
278
}
279
+ return formatted
290
280
},
291
281
})
292
282
result , resp := executeTest (t , h , req )
0 commit comments