From 4e8abf0e95ba86cb033c98041a288c7ea494de62 Mon Sep 17 00:00:00 2001 From: Brandon Fish Date: Fri, 5 Mar 2021 16:34:39 -0600 Subject: [PATCH] Initialize error data using constructors directly --- lib/grape/endpoint.rb | 2 +- lib/grape/parser/json.rb | 2 +- lib/grape/parser/xml.rb | 2 +- lib/grape/request.rb | 2 +- lib/grape/validations/validators/base.rb | 2 +- lib/grape/validations/validators/multiple_params_base.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/grape/endpoint.rb b/lib/grape/endpoint.rb index 7a8439692e..068e1ca0af 100644 --- a/lib/grape/endpoint.rb +++ b/lib/grape/endpoint.rb @@ -255,7 +255,7 @@ def run run_filters befores, :before if (allowed_methods = env[Grape::Env::GRAPE_ALLOWED_METHODS]) - raise Grape::Exceptions::MethodNotAllowed, header.merge('Allow' => allowed_methods) unless options? + raise Grape::Exceptions::MethodNotAllowed.new(header.merge('Allow' => allowed_methods)) unless options? header 'Allow', allowed_methods response_object = '' status 204 diff --git a/lib/grape/parser/json.rb b/lib/grape/parser/json.rb index 7f72c9a949..4e665a1ec2 100644 --- a/lib/grape/parser/json.rb +++ b/lib/grape/parser/json.rb @@ -8,7 +8,7 @@ def call(object, _env) ::Grape::Json.load(object) rescue ::Grape::Json::ParseError # handle JSON parsing errors via the rescue handlers or provide error message - raise Grape::Exceptions::InvalidMessageBody, 'application/json' + raise Grape::Exceptions::InvalidMessageBody.new('application/json') end end end diff --git a/lib/grape/parser/xml.rb b/lib/grape/parser/xml.rb index 20cde6e272..930c57f13e 100644 --- a/lib/grape/parser/xml.rb +++ b/lib/grape/parser/xml.rb @@ -8,7 +8,7 @@ def call(object, _env) ::Grape::Xml.parse(object) rescue ::Grape::Xml::ParseError # handle XML parsing errors via the rescue handlers or provide error message - raise Grape::Exceptions::InvalidMessageBody, 'application/xml' + raise Grape::Exceptions::InvalidMessageBody.new('application/xml') end end end diff --git a/lib/grape/request.rb b/lib/grape/request.rb index 0357477d50..ed97f3194a 100644 --- a/lib/grape/request.rb +++ b/lib/grape/request.rb @@ -16,7 +16,7 @@ def initialize(env, **options) def params @params ||= build_params rescue EOFError - raise Grape::Exceptions::EmptyMessageBody, content_type + raise Grape::Exceptions::EmptyMessageBody.new(content_type) end def headers diff --git a/lib/grape/validations/validators/base.rb b/lib/grape/validations/validators/base.rb index f8a2a1bcfc..84584e0b34 100644 --- a/lib/grape/validations/validators/base.rb +++ b/lib/grape/validations/validators/base.rb @@ -55,7 +55,7 @@ def validate!(params) end end - raise Grape::Exceptions::ValidationArrayErrors, array_errors if array_errors.any? + raise Grape::Exceptions::ValidationArrayErrors.new(array_errors) if array_errors.any? end def self.convert_to_short_name(klass) diff --git a/lib/grape/validations/validators/multiple_params_base.rb b/lib/grape/validations/validators/multiple_params_base.rb index 03867ff1ae..9ed0b6b969 100644 --- a/lib/grape/validations/validators/multiple_params_base.rb +++ b/lib/grape/validations/validators/multiple_params_base.rb @@ -16,7 +16,7 @@ def validate!(params) end end - raise Grape::Exceptions::ValidationArrayErrors, array_errors if array_errors.any? + raise Grape::Exceptions::ValidationArrayErrors.new(array_errors) if array_errors.any? end private