Skip to content

Commit

Permalink
error_response and error! have same signature. Fixes ruby-grape#889.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunny Juneja committed Jan 23, 2015
1 parent 567e779 commit 6c5f46d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/grape/middleware/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,19 @@ def handle_error(e)
error_response(message: e.message, backtrace: e.backtrace)
end

def error_response(error = {})
status = error[:status] || options[:default_status]
message = error[:message] || options[:default_message]
headers = { 'Content-Type' => content_type }
def error_response(error = {}, status = nil, headers = {})
status ||= (error[:status] || options[:default_status])
headers = { 'Content-Type' => content_type }.merge(headers)
headers.merge!(error[:headers]) if error[:headers].is_a?(Hash)
backtrace = error[:backtrace] || []
error = error.except(:backtrace, :status, :headers) if error.is_a?(Hash)
if error.is_a?(Grape::Exceptions::Base)
message = error[:message]
elsif error.is_a?(Hash) && error.count == 0
message = options[:default_message]
else
message = error
end
rack_response(format_message(message, backtrace), status, headers)
end

Expand Down

0 comments on commit 6c5f46d

Please sign in to comment.