Add and apply Style/RedundantBegin rubocop rule

We're about to add code which might fall into the `RedundantBegin`
category, so we're adding the rule in order to prevent that.
This commit is contained in:
Javi Martín
2024-10-30 15:55:29 +01:00
parent 9f38ed6bae
commit 07202fea10
9 changed files with 109 additions and 124 deletions

View File

@@ -9,25 +9,23 @@ class GraphqlController < ApplicationController
class QueryStringError < StandardError; end
def execute
begin
raise GraphqlController::QueryStringError if query_string.nil?
raise GraphqlController::QueryStringError if query_string.nil?
result = ConsulSchema.execute(
query_string,
variables: prepare_variables,
context: {},
operation_name: params[:operationName]
)
render json: result
rescue GraphqlController::QueryStringError
render json: { message: "Query string not present" }, status: :bad_request
rescue JSON::ParserError
render json: { message: "Error parsing JSON" }, status: :bad_request
rescue GraphQL::ParseError
render json: { message: "Query string is not valid JSON" }, status: :bad_request
rescue ArgumentError => e
render json: { message: e.message }, status: :bad_request
end
result = ConsulSchema.execute(
query_string,
variables: prepare_variables,
context: {},
operation_name: params[:operationName]
)
render json: result
rescue GraphqlController::QueryStringError
render json: { message: "Query string not present" }, status: :bad_request
rescue JSON::ParserError
render json: { message: "Error parsing JSON" }, status: :bad_request
rescue GraphQL::ParseError
render json: { message: "Query string is not valid JSON" }, status: :bad_request
rescue ArgumentError => e
render json: { message: e.message }, status: :bad_request
end
private