Skip to content

Commit

Permalink
feat: use Pact::Error subclass instead of RuntimeErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Aug 6, 2018
1 parent f31d235 commit a15dd3e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/pact/mock_service/client.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
require 'net/http'
require 'pact/mock_service/interaction_decorator'
require 'pact/errors'

module Pact
module MockService

class VerificationFailedError < Pact::Error; end
class AddInteractionError < Pact::Error; end
class WritePactError < Pact::Error; end

class Client

MOCK_SERVICE_ADMINISTRATON_HEADERS = {'X-Pact-Mock-Service' => 'true'}
Expand All @@ -13,7 +19,7 @@ def initialize port

def verify example_description
response = http.request_get("/interactions/verification?example_description=#{CGI.escape(example_description)}", MOCK_SERVICE_ADMINISTRATON_HEADERS)
raise "\e[31m#{response.body}\e[m" unless response.is_a? Net::HTTPSuccess
raise VerificationFailedError.new("\e[31m#{response.body}\e[m") unless response.is_a? Net::HTTPSuccess
end

def log msg
Expand All @@ -37,7 +43,7 @@ def add_expected_interaction interaction
interaction_json(interaction),
MOCK_SERVICE_ADMINISTRATON_HEADERS.merge("Content-Type" => "application/json")
)
raise "\e[31m#{response.body}\e[m" unless response.is_a? Net::HTTPSuccess
raise AddInteractionError.new("\e[31m#{response.body}\e[m") unless response.is_a? Net::HTTPSuccess
end

def self.clear_interactions port, example_description
Expand All @@ -46,7 +52,7 @@ def self.clear_interactions port, example_description

def write_pact pacticipant_details
response = http.request_post("/pact", pacticipant_details.to_json, MOCK_SERVICE_ADMINISTRATON_HEADERS.merge("Content-Type" => "application/json"))
raise "\e[31m#{response.body}\e[m" unless response.is_a? Net::HTTPSuccess
raise WritePactError.new("\e[31m#{response.body}\e[m") unless response.is_a? Net::HTTPSuccess
response.body
end

Expand All @@ -67,7 +73,6 @@ def wait_until_true timeout=3, interval=0.1
def interaction_json interaction
Pact::MockService::InteractionDecorator.new(interaction).to_json
end

end
end
end
end

0 comments on commit a15dd3e

Please sign in to comment.