aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/graphql-go/graphql/gqlerrors/formatted.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/graphql-go/graphql/gqlerrors/formatted.go')
-rw-r--r--vendor/github.com/graphql-go/graphql/gqlerrors/formatted.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/vendor/github.com/graphql-go/graphql/gqlerrors/formatted.go b/vendor/github.com/graphql-go/graphql/gqlerrors/formatted.go
new file mode 100644
index 00000000..3a1f8853
--- /dev/null
+++ b/vendor/github.com/graphql-go/graphql/gqlerrors/formatted.go
@@ -0,0 +1,51 @@
+package gqlerrors
+
+import (
+ "errors"
+
+ "github.com/graphql-go/graphql/language/location"
+)
+
+type FormattedError struct {
+ Message string `json:"message"`
+ Locations []location.SourceLocation `json:"locations"`
+}
+
+func (g FormattedError) Error() string {
+ return g.Message
+}
+
+func NewFormattedError(message string) FormattedError {
+ err := errors.New(message)
+ return FormatError(err)
+}
+
+func FormatError(err error) FormattedError {
+ switch err := err.(type) {
+ case FormattedError:
+ return err
+ case *Error:
+ return FormattedError{
+ Message: err.Error(),
+ Locations: err.Locations,
+ }
+ case Error:
+ return FormattedError{
+ Message: err.Error(),
+ Locations: err.Locations,
+ }
+ default:
+ return FormattedError{
+ Message: err.Error(),
+ Locations: []location.SourceLocation{},
+ }
+ }
+}
+
+func FormatErrors(errs ...error) []FormattedError {
+ formattedErrors := []FormattedError{}
+ for _, err := range errs {
+ formattedErrors = append(formattedErrors, FormatError(err))
+ }
+ return formattedErrors
+}