Skip to content

Commit 2f05060

Browse files
authored
Merge pull request #142 from ryanhertz/errors-in-errors
include the errors from the response in the instance of ClientErrors
2 parents 98a0f9f + 16302fe commit 2f05060

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v1.4.18
2+
- include the errors from the response in the instance of ClientErrors
3+
14
v1.4.17
25
- use '/flexmls/listings' for PUT
36

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.17
1+
1.4.18

lib/spark_api/errors.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ module ResponseCodes
2121
# Errors built from API responses
2222
class InvalidResponse < StandardError; end
2323
class ClientError < StandardError
24-
attr_reader :code, :status, :details, :request_path
24+
attr_reader :code, :status, :details, :request_path, :errors
2525
def initialize (options = {})
2626
# Support the standard initializer for errors
2727
opts = options.is_a?(Hash) ? options : {:message => options.to_s}
2828
@code = opts[:code]
2929
@status = opts[:status]
3030
@details = opts[:details]
3131
@request_path = opts[:request_path]
32+
@errors = opts[:errors]
3233
super(opts[:message])
3334
end
3435

lib/spark_api/faraday_middleware.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def on_complete(env)
4040
:request_path => env[:url],
4141
:message => response.message,
4242
:code => response.code,
43-
:status => env[:status]
43+
:status => env[:status],
44+
:errors => body['D']['Errors']
4445
}
4546

4647
case env[:status]

spec/unit/spark_api/faraday_middleware_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@
4848
"Code": "0000"
4949
}}']
5050
}
51+
stub.get('/badresourcerequest') { [409, {}, '{"D": {
52+
"Message": "FlexmlsApiResponse::Errors::Errors",
53+
"Code": 1053,
54+
"Success": false,
55+
"Errors": "Some errors and stuff."
56+
}}']
57+
}
5158
stub.get('/invalidjson') { [200, {}, '{"OMG": "THIS IS NOT THE API JSON THAT I KNOW AND <3!!!"}'] }
5259
stub.get('/garbage') { [200, {}, 'THIS IS TOTAL GARBAGE!'] }
5360
end
@@ -85,6 +92,12 @@
8592
response.results.length.should be > 0
8693
end
8794

95+
it "should include the errors in the response" do
96+
expect { @connection.get('/badresourcerequest')}.to raise_error(SparkApi::BadResourceRequest){ |e|
97+
e.errors.should == "Some errors and stuff."
98+
}
99+
end
100+
88101
end
89102

90103
describe "#decompress_body" do

0 commit comments

Comments
 (0)