Merge pull request #8918 from tchak/graphql-add-error-codes

ETQ intégrateur API, je voudrais avoir des codes d'erreur plus précis
This commit is contained in:
github-merge-queue[bot] 2023-04-19 09:00:32 +00:00 committed by GitHub
commit a286af8a70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 125 additions and 22 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)
@ -50,7 +48,7 @@ class API::V2::Schema < GraphQL::Schema
when GroupeInstructeur
Types::GroupeInstructeurType
else
raise GraphQL::ExecutionError.new("Unexpected object: #{object}")
type_definition
end
end
@ -129,8 +127,13 @@ 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)
error.extensions = { code: :timeout }
Sentry.capture_exception(error, extra: query.context.query_info)
end
end

View file

@ -8,7 +8,7 @@ class API::V2::StoredQuery
when 'introspection'
GraphQL::Introspection::INTROSPECTION_QUERY
else
raise GraphQL::ExecutionError.new("No query with id \"#{query_id}\"")
raise GraphQL::ExecutionError.new("No query with id \"#{query_id}\"", extensions: { code: :bad_request })
end
end