gocardless_pro 2.9.0 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a89de0204c5098ce2b5049a622271defb672b0abf80ad4fc0d1f6ef3538f88b8
4
- data.tar.gz: ece535f8f59810a51656f5e01b2667db60488f73cbd953a66a86e8bfa48da1e5
3
+ metadata.gz: 06d8895916dd0f220182f39eb35a9c286f50288c84391984715f2362b142319d
4
+ data.tar.gz: d2839e1c60c82d2907980843abb9c8e1e6a911d7a157752be15cf773b8333b4d
5
5
  SHA512:
6
- metadata.gz: 5a793807b561f52c2abdf3989d335ffa14d6dbdb2509c5f11d27fefb29bf82b9cf73c4937640b76d2a35ac869704798401e7636fe7a9a590e4f1d110171da1d9
7
- data.tar.gz: e89fb66ba9c3b79e7f1c10e5b1812bee44a82bcd33526b018f963570c364cf8168bbc93574dd5ca4e5988b80d6aaa5665450edb62a76fbdb5f73ca244f065e93
6
+ metadata.gz: 4cb9c53de215e5ad3c01d83f0568e3b6fa58bd5fc50daa43de0115977cf49e0d74f9e47836d99d1c5c0b9eb51663b778c4de572c7a8190cb97650b1d6cfbfa62
7
+ data.tar.gz: e247fb19810b43ca4131471833e700734c77231f0ebb8109da023229846c63cb1a12df04d232d2430ad69ec46fc9ce6e51ed4dc7a09d9d9066467125c72a8408
data/README.md CHANGED
@@ -147,18 +147,14 @@ The most common use of a custom header would be to set a custom [idempotency key
147
147
 
148
148
  ### Handling failures
149
149
 
150
- When the API returns an error, the client will raise a corresponding one. There are four classes of error which could be thrown, all of which subclass `GoCardlessPro::Error`:
150
+ When the API itself returns an error, the client will raise a corresponding exception. There are four classes of exception which could be thrown, all of which subclass `GoCardlessPro::Error`:
151
151
 
152
152
  - `GoCardlessPro::GoCardlessError`
153
153
  - `GoCardlessPro::InvalidApiUsageError`
154
154
  - `GoCardlessPro::InvalidStateError`
155
155
  - `GoCardlessPro::ValidationError`
156
156
 
157
- These errors are fully documented in the [API documentation](https://developer.gocardless.com/api-reference/#overview-errors).
158
-
159
- When the API returns an `invalid_state` error due to an `idempotent_creation_conflict`, where possible, the library will automatically retrieve the existing record which was created using the idempotency key.
160
-
161
- All errors have the following methods to facilitate access to information in the API response:
157
+ These different types of error are fully documented in the [API documentation](https://developer.gocardless.com/api-reference/#overview-errors). Exceptions raised by the library have the following methods to provide access to information in the API response:
162
158
 
163
159
  - `#documentation_url`
164
160
  - `#message`
@@ -167,7 +163,15 @@ All errors have the following methods to facilitate access to information in the
167
163
  - `#request_id`
168
164
  - `#errors`
169
165
 
170
- If a timeout occurs, and the request being made is idempotent, the library will automatically retry the request up to 3 times before giving up and raising a `Faraday::TimeoutError` error.
166
+ When the API returns an `invalid_state` error due to an `idempotent_creation_conflict`, where possible, the library will automatically retrieve the existing record which was created using the idempotency key.
167
+
168
+ If the client is unable to connect to GoCardless, an appropriate exception will be raised, for example:
169
+
170
+ * `Faraday::TimeoutError`, in case of a timeout
171
+ * `Faraday::ConnectionFailed`, in case of a connection issue (e.g. problems with DNS resolution)
172
+ * `GoCardlessPro::ApiError`, for `5xx` errors returned from our infrastructure, but not by the API itself
173
+
174
+ If an error occurs which is likely to be resolved with a retry (e.g. a timeout or connection error), and the request being made is idempotent, the library will automatically retry the request twice (i.e. it will make up to 3 attempts) before giving up and raising an exception.
171
175
 
172
176
  ### Using the OAuth API
173
177
 
@@ -133,7 +133,7 @@ module GoCardlessPro
133
133
  'User-Agent' => user_agent.to_s,
134
134
  'Content-Type' => 'application/json',
135
135
  'GoCardless-Client-Library' => 'gocardless-pro-ruby',
136
- 'GoCardless-Client-Version' => '2.9.0',
136
+ 'GoCardless-Client-Version' => '2.10.0',
137
137
  },
138
138
  }
139
139
  end
@@ -3,8 +3,12 @@ require 'securerandom'
3
3
  module GoCardlessPro
4
4
  # A class that wraps an API request
5
5
  class Request
6
- MAX_NETWORK_RETRIES = 3
6
+ MAX_RETRIES = 3
7
7
  RETRY_DELAY = 0.5
8
+ RETRYABLE_EXCEPTIONS = [Faraday::TimeoutError,
9
+ Faraday::ConnectionFailed,
10
+ GoCardlessPro::ApiError,
11
+ GoCardlessPro::GoCardlessError].freeze
8
12
 
9
13
  # Initialize a request class, which makes calls to the API
10
14
  # @param connection
@@ -42,13 +46,14 @@ module GoCardlessPro
42
46
 
43
47
  def with_retries
44
48
  requests_attempted = 0
45
- total_requests_allowed = MAX_NETWORK_RETRIES + 1
49
+ total_requests_allowed = MAX_RETRIES
46
50
 
47
51
  begin
48
52
  yield
49
53
  rescue => exception
54
+ requests_attempted += 1
55
+
50
56
  if requests_attempted < total_requests_allowed && should_retry?(exception)
51
- requests_attempted += 1
52
57
  sleep(RETRY_DELAY)
53
58
  retry
54
59
  else
@@ -90,9 +95,7 @@ module GoCardlessPro
90
95
  private
91
96
 
92
97
  def should_retry?(exception)
93
- return true if exception.is_a?(Faraday::TimeoutError)
94
- return true if exception.is_a?(Faraday::ConnectionFailed)
95
- return true if exception.is_a?(GoCardlessPro::ApiError)
98
+ RETRYABLE_EXCEPTIONS.include?(exception.class)
96
99
  end
97
100
  end
98
101
  end
@@ -4,5 +4,5 @@ end
4
4
 
5
5
  module GoCardlessPro
6
6
  # Current version of the GC gem
7
- VERSION = '2.9.0'.freeze
7
+ VERSION = '2.10.0'.freeze
8
8
  end
@@ -563,7 +563,7 @@ describe GoCardlessPro::Services::CreditorBankAccountsService do
563
563
  expect(stub).to have_been_requested.twice
564
564
  end
565
565
 
566
- it 'retries 5XX errors' do
566
+ it 'retries 5XX errors, other than 500s' do
567
567
  stub_url = '/creditor_bank_accounts/:identity'.gsub(':identity', id)
568
568
 
569
569
  stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
@@ -575,6 +575,34 @@ describe GoCardlessPro::Services::CreditorBankAccountsService do
575
575
  get_response
576
576
  expect(stub).to have_been_requested.twice
577
577
  end
578
+
579
+ it 'retries 500 errors returned by the API' do
580
+ stub_url = '/creditor_bank_accounts/:identity'.gsub(':identity', id)
581
+
582
+ gocardless_error = {
583
+ 'error' => {
584
+ 'message' => 'Internal server error',
585
+ 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
586
+ 'errors' => [{
587
+ 'message' => 'Internal server error',
588
+ 'reason' => 'internal_server_error',
589
+ }],
590
+ 'type' => 'gocardless',
591
+ 'code' => 500,
592
+ 'request_id' => 'dummy_request_id',
593
+ 'id' => 'dummy_exception_id',
594
+ },
595
+ }
596
+
597
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
598
+ to_return(status: 500,
599
+ headers: response_headers,
600
+ body: gocardless_error.to_json).
601
+ then.to_return(status: 200, headers: response_headers)
602
+
603
+ get_response
604
+ expect(stub).to have_been_requested.twice
605
+ end
578
606
  end
579
607
  end
580
608
 
@@ -643,7 +643,7 @@ describe GoCardlessPro::Services::CreditorsService do
643
643
  expect(stub).to have_been_requested.twice
644
644
  end
645
645
 
646
- it 'retries 5XX errors' do
646
+ it 'retries 5XX errors, other than 500s' do
647
647
  stub_url = '/creditors/:identity'.gsub(':identity', id)
648
648
 
649
649
  stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
@@ -655,6 +655,34 @@ describe GoCardlessPro::Services::CreditorsService do
655
655
  get_response
656
656
  expect(stub).to have_been_requested.twice
657
657
  end
658
+
659
+ it 'retries 500 errors returned by the API' do
660
+ stub_url = '/creditors/:identity'.gsub(':identity', id)
661
+
662
+ gocardless_error = {
663
+ 'error' => {
664
+ 'message' => 'Internal server error',
665
+ 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
666
+ 'errors' => [{
667
+ 'message' => 'Internal server error',
668
+ 'reason' => 'internal_server_error',
669
+ }],
670
+ 'type' => 'gocardless',
671
+ 'code' => 500,
672
+ 'request_id' => 'dummy_request_id',
673
+ 'id' => 'dummy_exception_id',
674
+ },
675
+ }
676
+
677
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
678
+ to_return(status: 500,
679
+ headers: response_headers,
680
+ body: gocardless_error.to_json).
681
+ then.to_return(status: 200, headers: response_headers)
682
+
683
+ get_response
684
+ expect(stub).to have_been_requested.twice
685
+ end
658
686
  end
659
687
  end
660
688
 
@@ -563,7 +563,7 @@ describe GoCardlessPro::Services::CustomerBankAccountsService do
563
563
  expect(stub).to have_been_requested.twice
564
564
  end
565
565
 
566
- it 'retries 5XX errors' do
566
+ it 'retries 5XX errors, other than 500s' do
567
567
  stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
568
568
 
569
569
  stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
@@ -575,6 +575,34 @@ describe GoCardlessPro::Services::CustomerBankAccountsService do
575
575
  get_response
576
576
  expect(stub).to have_been_requested.twice
577
577
  end
578
+
579
+ it 'retries 500 errors returned by the API' do
580
+ stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
581
+
582
+ gocardless_error = {
583
+ 'error' => {
584
+ 'message' => 'Internal server error',
585
+ 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
586
+ 'errors' => [{
587
+ 'message' => 'Internal server error',
588
+ 'reason' => 'internal_server_error',
589
+ }],
590
+ 'type' => 'gocardless',
591
+ 'code' => 500,
592
+ 'request_id' => 'dummy_request_id',
593
+ 'id' => 'dummy_exception_id',
594
+ },
595
+ }
596
+
597
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
598
+ to_return(status: 500,
599
+ headers: response_headers,
600
+ body: gocardless_error.to_json).
601
+ then.to_return(status: 200, headers: response_headers)
602
+
603
+ get_response
604
+ expect(stub).to have_been_requested.twice
605
+ end
578
606
  end
579
607
  end
580
608
 
@@ -677,7 +677,7 @@ describe GoCardlessPro::Services::CustomersService do
677
677
  expect(stub).to have_been_requested.twice
678
678
  end
679
679
 
680
- it 'retries 5XX errors' do
680
+ it 'retries 5XX errors, other than 500s' do
681
681
  stub_url = '/customers/:identity'.gsub(':identity', id)
682
682
 
683
683
  stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
@@ -689,6 +689,34 @@ describe GoCardlessPro::Services::CustomersService do
689
689
  get_response
690
690
  expect(stub).to have_been_requested.twice
691
691
  end
692
+
693
+ it 'retries 500 errors returned by the API' do
694
+ stub_url = '/customers/:identity'.gsub(':identity', id)
695
+
696
+ gocardless_error = {
697
+ 'error' => {
698
+ 'message' => 'Internal server error',
699
+ 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
700
+ 'errors' => [{
701
+ 'message' => 'Internal server error',
702
+ 'reason' => 'internal_server_error',
703
+ }],
704
+ 'type' => 'gocardless',
705
+ 'code' => 500,
706
+ 'request_id' => 'dummy_request_id',
707
+ 'id' => 'dummy_exception_id',
708
+ },
709
+ }
710
+
711
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
712
+ to_return(status: 500,
713
+ headers: response_headers,
714
+ body: gocardless_error.to_json).
715
+ then.to_return(status: 200, headers: response_headers)
716
+
717
+ get_response
718
+ expect(stub).to have_been_requested.twice
719
+ end
692
720
  end
693
721
  end
694
722
 
@@ -345,7 +345,7 @@ describe GoCardlessPro::Services::EventsService do
345
345
  expect(stub).to have_been_requested.twice
346
346
  end
347
347
 
348
- it 'retries 5XX errors' do
348
+ it 'retries 5XX errors, other than 500s' do
349
349
  stub_url = '/events/:identity'.gsub(':identity', id)
350
350
 
351
351
  stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
@@ -357,6 +357,34 @@ describe GoCardlessPro::Services::EventsService do
357
357
  get_response
358
358
  expect(stub).to have_been_requested.twice
359
359
  end
360
+
361
+ it 'retries 500 errors returned by the API' do
362
+ stub_url = '/events/:identity'.gsub(':identity', id)
363
+
364
+ gocardless_error = {
365
+ 'error' => {
366
+ 'message' => 'Internal server error',
367
+ 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
368
+ 'errors' => [{
369
+ 'message' => 'Internal server error',
370
+ 'reason' => 'internal_server_error',
371
+ }],
372
+ 'type' => 'gocardless',
373
+ 'code' => 500,
374
+ 'request_id' => 'dummy_request_id',
375
+ 'id' => 'dummy_exception_id',
376
+ },
377
+ }
378
+
379
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
380
+ to_return(status: 500,
381
+ headers: response_headers,
382
+ body: gocardless_error.to_json).
383
+ then.to_return(status: 200, headers: response_headers)
384
+
385
+ get_response
386
+ expect(stub).to have_been_requested.twice
387
+ end
360
388
  end
361
389
  end
362
390
  end
@@ -257,7 +257,7 @@ describe GoCardlessPro::Services::MandateImportsService do
257
257
  expect(stub).to have_been_requested.twice
258
258
  end
259
259
 
260
- it 'retries 5XX errors' do
260
+ it 'retries 5XX errors, other than 500s' do
261
261
  stub_url = '/mandate_imports/:identity'.gsub(':identity', id)
262
262
 
263
263
  stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
@@ -269,6 +269,34 @@ describe GoCardlessPro::Services::MandateImportsService do
269
269
  get_response
270
270
  expect(stub).to have_been_requested.twice
271
271
  end
272
+
273
+ it 'retries 500 errors returned by the API' do
274
+ stub_url = '/mandate_imports/:identity'.gsub(':identity', id)
275
+
276
+ gocardless_error = {
277
+ 'error' => {
278
+ 'message' => 'Internal server error',
279
+ 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
280
+ 'errors' => [{
281
+ 'message' => 'Internal server error',
282
+ 'reason' => 'internal_server_error',
283
+ }],
284
+ 'type' => 'gocardless',
285
+ 'code' => 500,
286
+ 'request_id' => 'dummy_request_id',
287
+ 'id' => 'dummy_exception_id',
288
+ },
289
+ }
290
+
291
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
292
+ to_return(status: 500,
293
+ headers: response_headers,
294
+ body: gocardless_error.to_json).
295
+ then.to_return(status: 200, headers: response_headers)
296
+
297
+ get_response
298
+ expect(stub).to have_been_requested.twice
299
+ end
272
300
  end
273
301
  end
274
302
 
@@ -547,7 +547,7 @@ describe GoCardlessPro::Services::MandatesService do
547
547
  expect(stub).to have_been_requested.twice
548
548
  end
549
549
 
550
- it 'retries 5XX errors' do
550
+ it 'retries 5XX errors, other than 500s' do
551
551
  stub_url = '/mandates/:identity'.gsub(':identity', id)
552
552
 
553
553
  stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
@@ -559,6 +559,34 @@ describe GoCardlessPro::Services::MandatesService do
559
559
  get_response
560
560
  expect(stub).to have_been_requested.twice
561
561
  end
562
+
563
+ it 'retries 500 errors returned by the API' do
564
+ stub_url = '/mandates/:identity'.gsub(':identity', id)
565
+
566
+ gocardless_error = {
567
+ 'error' => {
568
+ 'message' => 'Internal server error',
569
+ 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
570
+ 'errors' => [{
571
+ 'message' => 'Internal server error',
572
+ 'reason' => 'internal_server_error',
573
+ }],
574
+ 'type' => 'gocardless',
575
+ 'code' => 500,
576
+ 'request_id' => 'dummy_request_id',
577
+ 'id' => 'dummy_exception_id',
578
+ },
579
+ }
580
+
581
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
582
+ to_return(status: 500,
583
+ headers: response_headers,
584
+ body: gocardless_error.to_json).
585
+ then.to_return(status: 200, headers: response_headers)
586
+
587
+ get_response
588
+ expect(stub).to have_been_requested.twice
589
+ end
562
590
  end
563
591
  end
564
592
 
@@ -579,7 +579,7 @@ describe GoCardlessPro::Services::PaymentsService do
579
579
  expect(stub).to have_been_requested.twice
580
580
  end
581
581
 
582
- it 'retries 5XX errors' do
582
+ it 'retries 5XX errors, other than 500s' do
583
583
  stub_url = '/payments/:identity'.gsub(':identity', id)
584
584
 
585
585
  stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
@@ -591,6 +591,34 @@ describe GoCardlessPro::Services::PaymentsService do
591
591
  get_response
592
592
  expect(stub).to have_been_requested.twice
593
593
  end
594
+
595
+ it 'retries 500 errors returned by the API' do
596
+ stub_url = '/payments/:identity'.gsub(':identity', id)
597
+
598
+ gocardless_error = {
599
+ 'error' => {
600
+ 'message' => 'Internal server error',
601
+ 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
602
+ 'errors' => [{
603
+ 'message' => 'Internal server error',
604
+ 'reason' => 'internal_server_error',
605
+ }],
606
+ 'type' => 'gocardless',
607
+ 'code' => 500,
608
+ 'request_id' => 'dummy_request_id',
609
+ 'id' => 'dummy_exception_id',
610
+ },
611
+ }
612
+
613
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
614
+ to_return(status: 500,
615
+ headers: response_headers,
616
+ body: gocardless_error.to_json).
617
+ then.to_return(status: 200, headers: response_headers)
618
+
619
+ get_response
620
+ expect(stub).to have_been_requested.twice
621
+ end
594
622
  end
595
623
  end
596
624
 
@@ -378,7 +378,7 @@ describe GoCardlessPro::Services::PayoutsService do
378
378
  expect(stub).to have_been_requested.twice
379
379
  end
380
380
 
381
- it 'retries 5XX errors' do
381
+ it 'retries 5XX errors, other than 500s' do
382
382
  stub_url = '/payouts/:identity'.gsub(':identity', id)
383
383
 
384
384
  stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
@@ -390,6 +390,34 @@ describe GoCardlessPro::Services::PayoutsService do
390
390
  get_response
391
391
  expect(stub).to have_been_requested.twice
392
392
  end
393
+
394
+ it 'retries 500 errors returned by the API' do
395
+ stub_url = '/payouts/:identity'.gsub(':identity', id)
396
+
397
+ gocardless_error = {
398
+ 'error' => {
399
+ 'message' => 'Internal server error',
400
+ 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
401
+ 'errors' => [{
402
+ 'message' => 'Internal server error',
403
+ 'reason' => 'internal_server_error',
404
+ }],
405
+ 'type' => 'gocardless',
406
+ 'code' => 500,
407
+ 'request_id' => 'dummy_request_id',
408
+ 'id' => 'dummy_exception_id',
409
+ },
410
+ }
411
+
412
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
413
+ to_return(status: 500,
414
+ headers: response_headers,
415
+ body: gocardless_error.to_json).
416
+ then.to_return(status: 200, headers: response_headers)
417
+
418
+ get_response
419
+ expect(stub).to have_been_requested.twice
420
+ end
393
421
  end
394
422
  end
395
423
  end
@@ -292,7 +292,7 @@ describe GoCardlessPro::Services::RedirectFlowsService do
292
292
  expect(stub).to have_been_requested.twice
293
293
  end
294
294
 
295
- it 'retries 5XX errors' do
295
+ it 'retries 5XX errors, other than 500s' do
296
296
  stub_url = '/redirect_flows/:identity'.gsub(':identity', id)
297
297
 
298
298
  stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
@@ -304,6 +304,34 @@ describe GoCardlessPro::Services::RedirectFlowsService do
304
304
  get_response
305
305
  expect(stub).to have_been_requested.twice
306
306
  end
307
+
308
+ it 'retries 500 errors returned by the API' do
309
+ stub_url = '/redirect_flows/:identity'.gsub(':identity', id)
310
+
311
+ gocardless_error = {
312
+ 'error' => {
313
+ 'message' => 'Internal server error',
314
+ 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
315
+ 'errors' => [{
316
+ 'message' => 'Internal server error',
317
+ 'reason' => 'internal_server_error',
318
+ }],
319
+ 'type' => 'gocardless',
320
+ 'code' => 500,
321
+ 'request_id' => 'dummy_request_id',
322
+ 'id' => 'dummy_exception_id',
323
+ },
324
+ }
325
+
326
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
327
+ to_return(status: 500,
328
+ headers: response_headers,
329
+ body: gocardless_error.to_json).
330
+ then.to_return(status: 200, headers: response_headers)
331
+
332
+ get_response
333
+ expect(stub).to have_been_requested.twice
334
+ end
307
335
  end
308
336
  end
309
337
 
@@ -515,7 +515,7 @@ describe GoCardlessPro::Services::RefundsService do
515
515
  expect(stub).to have_been_requested.twice
516
516
  end
517
517
 
518
- it 'retries 5XX errors' do
518
+ it 'retries 5XX errors, other than 500s' do
519
519
  stub_url = '/refunds/:identity'.gsub(':identity', id)
520
520
 
521
521
  stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
@@ -527,6 +527,34 @@ describe GoCardlessPro::Services::RefundsService do
527
527
  get_response
528
528
  expect(stub).to have_been_requested.twice
529
529
  end
530
+
531
+ it 'retries 500 errors returned by the API' do
532
+ stub_url = '/refunds/:identity'.gsub(':identity', id)
533
+
534
+ gocardless_error = {
535
+ 'error' => {
536
+ 'message' => 'Internal server error',
537
+ 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
538
+ 'errors' => [{
539
+ 'message' => 'Internal server error',
540
+ 'reason' => 'internal_server_error',
541
+ }],
542
+ 'type' => 'gocardless',
543
+ 'code' => 500,
544
+ 'request_id' => 'dummy_request_id',
545
+ 'id' => 'dummy_exception_id',
546
+ },
547
+ }
548
+
549
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
550
+ to_return(status: 500,
551
+ headers: response_headers,
552
+ body: gocardless_error.to_json).
553
+ then.to_return(status: 200, headers: response_headers)
554
+
555
+ get_response
556
+ expect(stub).to have_been_requested.twice
557
+ end
530
558
  end
531
559
  end
532
560
 
@@ -675,7 +675,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
675
675
  expect(stub).to have_been_requested.twice
676
676
  end
677
677
 
678
- it 'retries 5XX errors' do
678
+ it 'retries 5XX errors, other than 500s' do
679
679
  stub_url = '/subscriptions/:identity'.gsub(':identity', id)
680
680
 
681
681
  stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
@@ -687,6 +687,34 @@ describe GoCardlessPro::Services::SubscriptionsService do
687
687
  get_response
688
688
  expect(stub).to have_been_requested.twice
689
689
  end
690
+
691
+ it 'retries 500 errors returned by the API' do
692
+ stub_url = '/subscriptions/:identity'.gsub(':identity', id)
693
+
694
+ gocardless_error = {
695
+ 'error' => {
696
+ 'message' => 'Internal server error',
697
+ 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
698
+ 'errors' => [{
699
+ 'message' => 'Internal server error',
700
+ 'reason' => 'internal_server_error',
701
+ }],
702
+ 'type' => 'gocardless',
703
+ 'code' => 500,
704
+ 'request_id' => 'dummy_request_id',
705
+ 'id' => 'dummy_exception_id',
706
+ },
707
+ }
708
+
709
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
710
+ to_return(status: 500,
711
+ headers: response_headers,
712
+ body: gocardless_error.to_json).
713
+ then.to_return(status: 200, headers: response_headers)
714
+
715
+ get_response
716
+ expect(stub).to have_been_requested.twice
717
+ end
690
718
  end
691
719
  end
692
720
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gocardless_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-22 00:00:00.000000000 Z
11
+ date: 2018-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec