feat(graphql): global not found error handling

This commit is contained in:
Paul Chavard 2023-04-18 10:08:18 +02:00
parent fbae6d941d
commit f70532a844
3 changed files with 41 additions and 9 deletions

View file

@ -25,8 +25,6 @@ class API::V2::Schema < GraphQL::Schema
def self.object_from_id(id, ctx)
ApplicationRecord.record_from_typed_id(id)
rescue => e
raise GraphQL::ExecutionError.new(e.message, extensions: { code: :not_found })
end
def self.resolve_type(type_definition, object, ctx)
@ -129,6 +127,10 @@ class API::V2::Schema < GraphQL::Schema
super
end
rescue_from(ActiveRecord::RecordNotFound) do |_error, _object, _args, _ctx, field|
raise GraphQL::ExecutionError.new("#{field.type.unwrap.graphql_name} not found", extensions: { code: :not_found })
end
class Timeout < GraphQL::Schema::Timeout
def handle_timeout(error, query)
Sentry.capture_exception(error, extra: query.context.query_info)

View file

@ -26,13 +26,11 @@ module Types
demarche_number = demarche.number.presence || ApplicationRecord.id_from_typed_id(demarche.id)
Procedure
.includes(draft_revision: :procedure, published_revision: :procedure)
.find_by(id: demarche_number)
.find(demarche_number)
end
def demarche(number:)
Procedure.for_api_v2.find(number)
rescue => e
raise GraphQL::ExecutionError.new(e.message, extensions: { code: :not_found })
end
def dossier(number:)
@ -42,14 +40,10 @@ module Types
Dossier.visible_by_administration.for_api_v2.find(number)
end
DossierPreloader.load_one(dossier)
rescue => e
raise GraphQL::ExecutionError.new(e.message, extensions: { code: :not_found })
end
def groupe_instructeur(number:)
GroupeInstructeur.for_api_v2.find(number)
rescue => e
raise GraphQL::ExecutionError.new(e.message, extensions: { code: :not_found })
end
def self.accessible?(context)