Skip to content

Commit cbdaed4

Browse files
[TBT-220] Add cc timeout messsage (#1346)
* add cc timeout messsage * create custom timeout message- testing with 1 sec * refactor handler * syntax * refactor * revert ||= connection * refactor create_v2_subscitpion * add <br> to message * return timeout to 10 sec * remove empty line * add sepc for timeout
1 parent b4da19d commit cbdaed4

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

lib/travis/api/v3.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def location(env)
5252
UnprocessableEntity = ClientError .create('request unable to be processed due to semantic errors', status: 422)
5353
WrongCredentials = ClientError .create('access denied', status: 403)
5454
WrongParams = ClientError .create('wrong parameters')
55+
TimeoutError = ServerError .create("Credit card processing is currently taking longer than expected. Please check back in a few minutes and refresh the screen at that time.<br>We apologize for the inconvenience and appreciate your patience.", status: 504)
5556
end
5657
end
5758
end

lib/travis/api/v3/billing_client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ def create_subscription(subscription_data)
146146
def create_v2_subscription(subscription_data)
147147
response = connection.post('/v2/subscriptions', subscription_data)
148148
handle_v2_subscription_response(response)
149+
rescue Faraday::TimeoutError
150+
raise Travis::API::V3::TimeoutError
149151
end
150152

151153
def changetofree_v2_subscription(subscription_id, data)

spec/v3/billing_client_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@
231231
let(:subscription_data) {{ 'address' => 'Rigaer' }}
232232
subject { billing.create_v2_subscription(subscription_data) }
233233

234+
context 'when the connection times out' do
235+
before do
236+
allow_any_instance_of(Faraday::Connection).to receive(:post).and_raise(Faraday::TimeoutError)
237+
end
238+
239+
it 'raises a TimeoutError with the correct message and status' do
240+
expect { subject }.to raise_error(Travis::API::V3::TimeoutError, /Credit card processing is currently taking longer than expected/)
241+
end
242+
end
243+
234244
it 'requests the creation and returns the representation' do
235245
stubbed_request = stub_billing_request(:post, "/v2/subscriptions", auth_key: auth_key, user_id: user_id)
236246
.with(body: JSON.dump(subscription_data))

0 commit comments

Comments
 (0)