Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize error data using constructors directly #2165

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/parser/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/parser/xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/validations/validators/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/validations/validators/multiple_params_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down