From 3eae17b7cb010fab6e13b94e81f147e64e0f008a Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 29 Mar 2023 15:37:41 +0200 Subject: [PATCH] feat(graphql): log type and timeout errors --- app/graphql/api/v2/schema.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/graphql/api/v2/schema.rb b/app/graphql/api/v2/schema.rb index f3dd14657..831cdc906 100644 --- a/app/graphql/api/v2/schema.rb +++ b/app/graphql/api/v2/schema.rb @@ -121,7 +121,21 @@ class API::V2::Schema < GraphQL::Schema raise GraphQL::ExecutionError.new("An object of type #{error.type.graphql_name} was hidden due to permissions", extensions: { code: :unauthorized }) end - use GraphQL::Schema::Timeout, max_seconds: 10 + def self.type_error(error, ctx) + # Capture type errors in Sentry. Thouse errors are our responsability and usually linked to + # instances of "bad data". + Sentry.capture_exception(error) + super + end + + class Timeout < GraphQL::Schema::Timeout + def handle_timeout(error, query) + extra = { query: query.query_string, variables: query.provided_variables&.to_json } + Sentry.capture_exception(error, extra:) + end + end + + use Timeout, max_seconds: 10 use GraphQL::Batch use GraphQL::Backtrace