Intégration de Sentry

This commit is contained in:
2020-10-12 14:35:02 +02:00
parent 27458b5b94
commit d0cd9842ea
5 changed files with 195 additions and 1 deletions

View File

@ -1,10 +1,15 @@
package route
import (
"context"
"net/http"
"path"
"time"
"github.com/99designs/gqlgen/graphql"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors"
"forge.cadoles.com/Cadoles/daddy/internal/config"
"forge.cadoles.com/Cadoles/daddy/internal/graph"
"forge.cadoles.com/Cadoles/daddy/internal/graph/generated"
@ -44,6 +49,19 @@ func Mount(r *chi.Mux, config *config.Config) error {
generated.NewExecutableSchema(gqlConfig),
)
gql.SetRecoverFunc(func(ctx context.Context, err interface{}) error {
// Dispatch error to Sentry
if realErr, ok := err.(error); ok {
sentry.CaptureException(realErr)
}
if strErr, ok := err.(string); ok {
sentry.CaptureException(errors.New(strErr))
}
return graphql.DefaultRecover(ctx, err)
})
gql.AddTransport(transport.POST{})
gql.AddTransport(&transport.Websocket{
KeepAlivePingInterval: 10 * time.Second,