Skip to content

Commit c8f082e

Browse files
authored
Add internal server error exception (#74)
1 parent 75a734a commit c8f082e

File tree

5 files changed

+89
-14
lines changed

5 files changed

+89
-14
lines changed

Gemfile.lock

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
xpm_ruby (0.3.0)
4+
xpm_ruby (0.4.0)
55
activesupport
66
builder
77
dry-types
@@ -12,43 +12,55 @@ PATH
1212
GEM
1313
remote: https://rubygems.org/
1414
specs:
15-
activesupport (7.0.4.1)
15+
activesupport (7.1.1)
16+
base64
17+
bigdecimal
1618
concurrent-ruby (~> 1.0, >= 1.0.2)
19+
connection_pool (>= 2.2.5)
20+
drb
1721
i18n (>= 1.6, < 2)
1822
minitest (>= 5.1)
23+
mutex_m
1924
tzinfo (~> 2.0)
2025
ast (2.4.2)
26+
base64 (0.1.1)
27+
bigdecimal (3.1.4)
2128
builder (3.2.4)
2229
byebug (11.1.3)
2330
coderay (1.1.3)
24-
concurrent-ruby (1.1.10)
31+
concurrent-ruby (1.2.2)
32+
connection_pool (2.4.1)
2533
diff-lcs (1.5.0)
26-
dry-core (1.0.0)
34+
drb (2.1.1)
35+
ruby2_keywords
36+
dry-core (1.0.1)
2737
concurrent-ruby (~> 1.0)
2838
zeitwerk (~> 2.6)
2939
dry-inflector (1.0.0)
3040
dry-logic (1.5.0)
3141
concurrent-ruby (~> 1.0)
3242
dry-core (~> 1.0, < 2)
3343
zeitwerk (~> 2.6)
34-
dry-types (1.7.0)
44+
dry-types (1.7.1)
3545
concurrent-ruby (~> 1.0)
36-
dry-core (~> 1.0, < 2)
37-
dry-inflector (~> 1.0, < 2)
38-
dry-logic (>= 1.4, < 2)
46+
dry-core (~> 1.0)
47+
dry-inflector (~> 1.0)
48+
dry-logic (~> 1.4)
3949
zeitwerk (~> 2.6)
40-
faraday (2.7.4)
50+
faraday (2.7.11)
51+
base64
4152
faraday-net_http (>= 2.0, < 3.1)
4253
ruby2_keywords (>= 0.0.4)
4354
faraday-encoding (0.0.5)
4455
faraday
4556
faraday-net_http (3.0.2)
46-
i18n (1.12.0)
57+
i18n (1.14.1)
4758
concurrent-ruby (~> 1.0)
4859
json (2.6.3)
4960
method_source (1.0.0)
50-
minitest (5.17.0)
51-
ox (2.14.13)
61+
minitest (5.20.0)
62+
mutex_m (0.1.2)
63+
ox (2.14.17)
5264
parallel (1.22.1)
5365
parser (3.2.0.0)
5466
ast (~> 2.4.1)
@@ -94,11 +106,11 @@ GEM
94106
rubocop-capybara (~> 2.17)
95107
ruby-progressbar (1.11.0)
96108
ruby2_keywords (0.0.5)
97-
tzinfo (2.0.5)
109+
tzinfo (2.0.6)
98110
concurrent-ruby (~> 1.0)
99111
unicode-display_width (2.4.2)
100112
vcr (6.1.0)
101-
zeitwerk (2.6.6)
113+
zeitwerk (2.6.12)
102114

103115
PLATFORMS
104116
ruby

lib/xpm_ruby.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class ConnectionFailed < Error; end
1717

1818
class ConnectionTimeout < Error; end
1919

20+
class InternalServerError < Error; end
21+
2022
class RateLimitExceeded < Error
2123
attr_reader :details
2224

lib/xpm_ruby/connection.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def handle_response(response)
8282
when 403 # this can happen with a bad xero_tenant_id
8383
detail = JSON.parse(response.body)["Detail"]
8484
raise Forbidden.new(detail)
85+
when 500
86+
raise InternalServerError.new(response.reason_phrase)
8587
when 503
8688
detail = JSON.parse(response.body)["Detail"]
8789
raise NotAvailable.new(detail)

spec/vcr_cassettes/xpm_ruby/connection/get/internal_server_error.yml

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/xpm_ruby/connection_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ module XpmRuby
6767
end
6868
end
6969

70+
context "with XPM API returns internal server error" do
71+
it "should raise an error" do
72+
VCR.use_cassette("xpm_ruby/connection/get/internal_server_error") do
73+
connection = Connection.new(access_token: "bad_token", xero_tenant_id: xero_tenant_id)
74+
expect { connection.get(endpoint: "staff.api/list") }.to raise_error(XpmRuby::InternalServerError)
75+
end
76+
end
77+
end
78+
7079
context "when API rate limit is exceeded" do
7180
it "should raise an error with details" do
7281
VCR.use_cassette("xpm_ruby/connection/get/rate_limit_exceeded") do

0 commit comments

Comments
 (0)