Skip to content

Commit a15dd3e

Browse files
committed
feat: use Pact::Error subclass instead of RuntimeErrors
1 parent f31d235 commit a15dd3e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/pact/mock_service/client.rb

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
require 'net/http'
22
require 'pact/mock_service/interaction_decorator'
3+
require 'pact/errors'
34

45
module Pact
56
module MockService
7+
8+
class VerificationFailedError < Pact::Error; end
9+
class AddInteractionError < Pact::Error; end
10+
class WritePactError < Pact::Error; end
11+
612
class Client
713

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

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

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

4349
def self.clear_interactions port, example_description
@@ -46,7 +52,7 @@ def self.clear_interactions port, example_description
4652

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

@@ -67,7 +73,6 @@ def wait_until_true timeout=3, interval=0.1
6773
def interaction_json interaction
6874
Pact::MockService::InteractionDecorator.new(interaction).to_json
6975
end
70-
7176
end
7277
end
73-
end
78+
end

0 commit comments

Comments
 (0)