Skip to content

Commit

Permalink
Merge pull request #2165 from bjfish/bjfish/initialize-custom-error-data
Browse files Browse the repository at this point in the history
Initialize error data using constructors directly
  • Loading branch information
dblock committed Mar 6, 2021
2 parents e0f412c + 4e8abf0 commit 3ade791
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
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

0 comments on commit 3ade791

Please sign in to comment.