@@ -2,7 +2,6 @@ package handler_test
22
33import (
44 "encoding/json"
5- "errors"
65 "fmt"
76 "io/ioutil"
87 "net/http"
@@ -215,15 +214,15 @@ func TestHandler_BasicQuery_WithRootObjFn(t *testing.T) {
215214}
216215
217216type customError struct {
218- error
217+ message string
219218}
220219
221220func (e customError ) Error () string {
222- return e . error . Error ( )
221+ return fmt . Sprintf ( "%s" , e . message )
223222}
224223
225224func TestHandler_BasicQuery_WithFormatErrorFn (t * testing.T ) {
226- resolverError := customError {error : errors . New ( "resolver error" ) }
225+ resolverError := customError {message : "resolver error" }
227226 myNameQuery := graphql .NewObject (graphql.ObjectConfig {
228227 Name : "Query" ,
229228 Fields : graphql.Fields {
@@ -252,9 +251,6 @@ func TestHandler_BasicQuery_WithFormatErrorFn(t *testing.T) {
252251 },
253252 },
254253 Path : []interface {}{"name" },
255- Extensions : map [string ]interface {}{
256- "fromFormatFn" : "FROM_FORMAT_FN" ,
257- },
258254 }
259255
260256 expected := & graphql.Result {
@@ -271,22 +267,16 @@ func TestHandler_BasicQuery_WithFormatErrorFn(t *testing.T) {
271267 h := handler .New (& handler.Config {
272268 Schema : & myNameSchema ,
273269 Pretty : true ,
274- FormatErrorFn : func (err gqlerrors. FormattedError ) gqlerrors.FormattedError {
270+ FormatErrorFn : func (err error ) gqlerrors.FormattedError {
275271 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 )
279276 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 ))
289278 }
279+ return formatted
290280 },
291281 })
292282 result , resp := executeTest (t , h , req )
0 commit comments