Skip to content

Commit

Permalink
Merge pull request #3 from nrfta/bug/runtile-type-error
Browse files Browse the repository at this point in the history
Fix display error from runtime.TypeAssertionError
  • Loading branch information
josemarluedke authored Feb 10, 2021
2 parents a9db4a6 + 817cd14 commit 2310d05
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions errorhandling/error_handling.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
goErrors "errors"
"runtime"

"github.com/99designs/gqlgen/graphql"
"github.com/neighborly/go-errors"
Expand All @@ -26,6 +27,10 @@ type ErrorReporterFunc func(ctx context.Context, err error)

func ConfigureErrorPresenterFunc(reporterFunc ErrorReporterFunc) graphql.ErrorPresenterFunc {
return func(ctx context.Context, e error) *gqlerror.Error {
if _, ok := e.(*runtime.TypeAssertionError); ok {
return graphql.DefaultErrorPresenter(ctx, e)
}

err := graphql.DefaultErrorPresenter(ctx, e)
customError := createCustomError(err)

Expand All @@ -34,6 +39,9 @@ func ConfigureErrorPresenterFunc(reporterFunc ErrorReporterFunc) graphql.ErrorPr
customError = createCustomError(gqlerr.Unwrap())
}

if customError == nil {
return err
}
reportAndLogError(reporterFunc, ctx, customError)

err.Message = errors.DisplayMessage(customError)
Expand Down

0 comments on commit 2310d05

Please sign in to comment.