Skip to content

Commit

Permalink
Merge pull request #4 from guilhermehubner/TypeInErrors
Browse files Browse the repository at this point in the history
Adicionando type em errors
  • Loading branch information
Guilherme Hübner Franco committed Jun 26, 2018
2 parents 5dbc3a1 + dff49f6 commit 2c68a78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gqlerrors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"github.com/StudioSol/graphql/language/source"
)

type ErrorWithType interface {
Error() string
Type() string
}

type Error struct {
Message string
Stack string
Expand Down
7 changes: 7 additions & 0 deletions gqlerrors/formatted.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
type FormattedError struct {
Message string `json:"message"`
Locations []location.SourceLocation `json:"locations"`
Type string `json:"type,omitempty"`
}

func (g FormattedError) Error() string {
Expand All @@ -34,6 +35,12 @@ func FormatError(err error) FormattedError {
Message: err.Error(),
Locations: err.Locations,
}
case ErrorWithType:
return FormattedError{
Message: err.Error(),
Locations: []location.SourceLocation{},
Type: err.Type(),
}
default:
return FormattedError{
Message: err.Error(),
Expand Down

0 comments on commit 2c68a78

Please sign in to comment.