Skip to content

Commit a503822

Browse files
authored
Merge pull request #326 from zendesk/grosser/info
show what exactly went wrong
2 parents 91e7a20 + ed3587d commit a503822

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ script:
1212
- bundle exec rake
1313
- bundle exec rubocop
1414

15+
branches:
16+
only: master
17+
1518
sudo: false

lib/zendesk_api/error.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
# tested via spec/core/middleware/response/raise_error_spec.rb
12
module ZendeskAPI
23
module Error
34
class ClientError < Faraday::Error::ClientError
45
attr_reader :wrapped_exception
6+
7+
def to_s
8+
"#{super} -- #{response.method} #{response.url}"
9+
end
510
end
611

712
class RecordInvalid < ClientError
8-
attr_accessor :response, :errors
13+
attr_accessor :errors
914

10-
def initialize(response)
11-
@response = response
15+
def initialize(*)
16+
super
1217

1318
if response[:body].is_a?(Hash)
1419
@errors = response[:body]["details"] || response[:body]["description"]
@@ -18,7 +23,7 @@ def initialize(response)
1823
end
1924

2025
def to_s
21-
"#{self.class.name}: #{@errors.to_s}"
26+
"#{self.class.name}: #{@errors}"
2227
end
2328
end
2429

spec/core/middleware/response/raise_error_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@
6666
context "with status in 3XX" do
6767
let(:status) { 302 }
6868

69-
it "should raise NetworkError" do
69+
it "raises NetworkError" do
7070
expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::NetworkError)
7171
end
72+
73+
it "tells the user what was going on" do
74+
expect { client.connection.get "/non_existent" }.to raise_error("the server responded with status 302 -- get https://my.zendesk.com/non_existent")
75+
end
7276
end
7377

7478
context "with status = 422" do

0 commit comments

Comments
 (0)