Skip to content
Open
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/hammer_cli_foreman/exception_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def handle_foreman_unauthorized(e)
def handle_unprocessable_entity(e)
response = JSON.parse(e.response)
response = HammerCLIForeman.record_to_common_format(response) unless response.has_key?('message')
print_error response['message'] || response['full_messages']
print_error response['message'] || response['full_messages'] || response['displayMessage']
Comment thread
chris1984 marked this conversation as resolved.
HammerCLI::EX_DATAERR
end

Expand Down
11 changes: 11 additions & 0 deletions test/unit/exception_handler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
_(err_code).must_equal HammerCLI::EX_DATAERR
end

it "should print displayMessage on unprocessable entity exception" do
response = <<-RESPONSE
{"displayMessage":"Validation failed: Cannot add content view environment to content facet.","errors":{"base":["Cannot add content view environment to content facet."]}}
RESPONSE

ex = RestClient::UnprocessableEntity.new(response)
output.expects(:print_error).with(heading, "Validation failed: Cannot add content view environment to content facet.")
err_code = handler.handle_exception(ex, :heading => heading)
_(err_code).must_equal HammerCLI::EX_DATAERR
end

it "should handle argument error" do
ex = ArgumentError.new
output.expects(:print_error).with(heading, ex.message)
Expand Down
Loading