Skip to content

Commit

Permalink
feat: move $.message to $.error.message in error response body
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jun 15, 2018
1 parent 44cdeee commit 803c025
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/pact_broker/api/resources/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class ErrorHandler
def self.call e, request, response
logger.error e
logger.error e.backtrace
response_body = { :message => e.message }
response_body = { error: { :message => e.message } }
if PactBroker.configuration.show_backtrace_in_error_response?
response_body[:backtrace] = e.backtrace
response_body[:error][:backtrace] = e.backtrace
end
response.body = response_body.to_json
report(e, request) if reportable?(e)
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/pact_broker/api/resources/error_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ module Resources
end
end

it "creates a json error response body" do
expect(response).to receive(:body=) do | body |
expect(JSON.parse(body)['error']).to include 'message' => 'test error'
end
subject
end


context "when show_backtrace_in_error_response? is true" do
before do
allow(PactBroker.configuration).to receive(:show_backtrace_in_error_response?).and_return(true)
Expand Down
7 changes: 1 addition & 6 deletions spec/lib/pact_broker/api/resources/pacticipant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@ module Resources

it "returns an error message" do
subject
expect(response_body[:message]).to eq "An error"
end

it "returns the backtrace" do
subject
expect(response_body[:backtrace]).to be_instance_of(Array)
expect(response_body[:error][:message]).to eq "An error"
end
end
end
Expand Down
7 changes: 1 addition & 6 deletions spec/lib/pact_broker/api/resources/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ module Resources

it "returns an error message" do
subject
expect(response_body[:message]).to eq "An error"
end

it "returns the backtrace" do
subject
expect(response_body[:backtrace]).to be_instance_of(Array)
expect(response_body[:error][:message]).to eq "An error"
end
end
end
Expand Down

0 comments on commit 803c025

Please sign in to comment.