diff --git a/lib/pact_broker/client/base_client.rb b/lib/pact_broker/client/base_client.rb index 40907e14..0cda57a9 100644 --- a/lib/pact_broker/client/base_client.rb +++ b/lib/pact_broker/client/base_client.rb @@ -125,7 +125,7 @@ def url_for_relation relation_name, params end url else - raise PactBroker::Client::RelationNotFound.new("Could not find relation #{relation_name} in index resource. Try upgrading your Pact Broker as the feature you require may not exist in your version.") + raise PactBroker::Client::RelationNotFound.new("Could not find relation #{relation_name} in index resource. Try upgrading your Pact Broker as the feature you require may not exist in your version. If you are using Pactflow, you may not have the permissions required for this action.") end end end diff --git a/lib/pact_broker/client/hal/entity.rb b/lib/pact_broker/client/hal/entity.rb index 27a65d24..d5790f90 100644 --- a/lib/pact_broker/client/hal/entity.rb +++ b/lib/pact_broker/client/hal/entity.rb @@ -91,11 +91,11 @@ def _links(key) end def _link!(key) - _link(key) or raise RelationNotFoundError.new("Could not find relation '#{key}' in resource at #{@href}") + _link(key) or raise RelationNotFoundError.new(relation_not_found_error_message(key, @href)) end def _links!(key) - _links(key) or raise RelationNotFoundError.new("Could not find relation '#{key}' in resource at #{@href}") + _links(key) or raise RelationNotFoundError.new(relation_not_found_error_message(key, @href)) end def embedded_entity @@ -161,6 +161,10 @@ def assert_success!(_ignored = nil) def self_href(entity_hash) entity_hash["_links"] && entity_hash["_links"]["self"] && entity_hash["_links"]["self"]["href"] end + + def relation_not_found_error_message(key, href) + "Could not find relation '#{key}' in resource at #{href}. The most likely reason for this is that you are on an old version of the Pact Broker and you need to upgrade, or you are using Pactflow and you don't have the permissions required for this action." + end end class ErrorEntity < Entity diff --git a/lib/pact_broker/client/webhooks/create.rb b/lib/pact_broker/client/webhooks/create.rb index f90381b2..ab5282a0 100644 --- a/lib/pact_broker/client/webhooks/create.rb +++ b/lib/pact_broker/client/webhooks/create.rb @@ -50,7 +50,7 @@ def create_webhook_with_optional_consumer_and_provider return error_result(CREATING_WEBHOOK_WITH_UUID_NOT_SUPPORTED) end else - webhook_entity = index_entity._link("pb:webhooks").post(request_body_with_optional_consumer_and_provider) + webhook_entity = index_entity._link!("pb:webhooks").post(request_body_with_optional_consumer_and_provider) end if webhook_entity.response.status == 405 diff --git a/spec/lib/pact_broker/client/hal/entity_spec.rb b/spec/lib/pact_broker/client/hal/entity_spec.rb index 742321cd..3091845a 100644 --- a/spec/lib/pact_broker/client/hal/entity_spec.rb +++ b/spec/lib/pact_broker/client/hal/entity_spec.rb @@ -112,7 +112,7 @@ module Hal context 'when the key does not exist' do it 'raises an error' do - expect { subject._link!('foo') }.to raise_error RelationNotFoundError, "Could not find relation 'foo' in resource at http://pact" + expect { subject._link!('foo') }.to raise_error RelationNotFoundError, /Could not find relation 'foo' in resource at http:\/\/pact/ end end end