Merge pull request #6657 from betagouv/sentry-ignore-parse-errors

GraphQL : affiche la cause des erreurs de syntaxe des requêtes
This commit is contained in:
Paul Chavard 2021-11-22 17:05:24 +03:00 committed by GitHub
commit e934d6ea30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,6 +8,8 @@ class API::V2::GraphqlController < API::V2::BaseController
operation_name: params[:operationName])
render json: result
rescue GraphQL::ParseError => exception
handle_parse_error(exception)
rescue => exception
if Rails.env.production?
handle_error_in_production(exception)
@ -88,6 +90,15 @@ class API::V2::GraphqlController < API::V2::BaseController
end
end
def handle_parse_error(exception)
render json: {
errors: [
{ message: exception.message }
],
data: nil
}, status: 400
end
def handle_error_in_development(exception)
logger.error exception.message
logger.error exception.backtrace.join("\n")