/
errors.go
65 lines (52 loc) · 1.99 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package graphqlws
import (
"errors"
"github.com/graphql-go/graphql/gqlerrors"
)
var (
ErrConnectionClosed = errors.New("connection already closed")
ErrUpgraderRequired = errors.New("upgrader required")
ErrSchemaRequired = errors.New("schema required")
ErrClientDoesNotImplementGraphqlWS = errors.New("client does not implement the `graphql-ws` subprotocol")
ErrSubscriptionNotFound = errors.New("subscription not found")
// ErrReinitializationForbidden is triggered when a `gqlConnectionInit` is
// received twice.
ErrReinitializationForbidden = errors.New("reinitalization forbidden")
// ErrConnectionNotFullyEstablished is triggered when a `gqlStart` is received
// without finishing a `gqlConnectionInit`.
ErrConnectionNotFullyEstablished = errors.New("connection not established")
// ErrInvalidTopic is triggered when a `Subscriber.SubscriberSubscribe`
// receives an invalid `Topic`.
ErrInvalidTopic = errors.New("invalid topic")
// ErrInvalidSubscriber is triggered when a `graphql.SubscribeParams.Subscriber`
// is not a instance that implements the `graphqlws.Subscriber` interface.
ErrInvalidSubscriber = errors.New("invalid subscriber")
)
type HandlerError struct {
defaultPrevented bool
propagationStopped bool
}
func (err *HandlerError) Error() string {
return ""
}
// PreventDefault set a flag for not executing the default implementation of an event.
func (err *HandlerError) PreventDefault() *HandlerError {
err.defaultPrevented = true
return err
}
// StopPropagation set a flag for not executing the subsequent handlers of an event.
func (err *HandlerError) StopPropagation() *HandlerError {
err.propagationStopped = true
return err
}
// ErrorsFromGraphQLErrors convert from GraphQL errors to regular errors.
func ErrorsFromGraphQLErrors(errors []gqlerrors.FormattedError) []error {
if len(errors) == 0 {
return nil
}
out := make([]error, len(errors))
for i := range errors {
out[i] = errors[i]
}
return out
}