File tree Expand file tree Collapse file tree 4 files changed +24
-12
lines changed Expand file tree Collapse file tree 4 files changed +24
-12
lines changed Original file line number Diff line number Diff line change 6
6
- vendor/**/*
7
7
- examples/**/*
8
8
9
- Metrics /LineLength :
9
+ Layout /LineLength :
10
10
Max : 120
11
11
12
12
Metrics/AbcSize :
Original file line number Diff line number Diff line change 1
1
## Next Release
2
2
Your contribution here.
3
3
4
+ * [ #167 ] ( https://github.com/bigcommerce/bigcommerce-api-ruby/pull/000 ) : Changes handling of HTTP response headers to handle lowercased titles. - [ @bc-zachary ] ( https://github.com/bc-zachary ) .
4
5
* [ #000 ] ( https://github.com/bigcommerce/bigcommerce-api-ruby/pull/000 ) : Brief description here. - [ @username ] ( https://github.com/username ) .
5
6
6
7
## 1.0.1
Original file line number Diff line number Diff line change 1
1
module Bigcommerce
2
2
class HttpError < StandardError
3
3
attr_accessor :response_headers
4
+
4
5
def initialize ( headers )
5
6
@response_headers = headers
6
7
end
@@ -41,17 +42,13 @@ module HttpErrors
41
42
42
43
def throw_http_exception! ( code , env )
43
44
return unless ERRORS . keys . include? code
44
- response_headers = { }
45
- unless env . body . empty?
46
- response_headers = begin
47
- JSON . parse ( env . body , symbolize_names : true )
48
- rescue StandardError
49
- { }
50
- end
51
- end
52
- unless env [ :response_headers ] && env [ :response_headers ] [ 'X-Retry-After' ] . nil?
53
- response_headers [ :retry_after ] = env [ :response_headers ] [ 'X-Retry-After' ] . to_i
45
+
46
+ response_headers = Faraday ::Utils ::Headers . new ( env . response_headers )
47
+
48
+ unless response_headers [ 'x-retry-after' ] . nil?
49
+ response_headers [ :retry_after ] = response_headers [ 'x-retry-after' ] . to_i
54
50
end
51
+
55
52
raise ERRORS [ code ] . new ( response_headers ) , env . body
56
53
end
57
54
end
Original file line number Diff line number Diff line change 7
7
8
8
before do
9
9
allow ( env ) . to receive ( :body ) { body }
10
- allow ( env ) . to receive ( :[] ) { headers }
10
+ allow ( env ) . to receive ( :response_headers ) { headers }
11
11
end
12
12
13
13
it '::ERRORS is not nil' do
43
43
end
44
44
end
45
45
46
+ context 'when have a body and lowercase response headers' do
47
+ let ( :body ) { JSON . generate ( { time : '1426184190' } ) }
48
+ let ( :headers ) { { 'x-retry-after' => 1 } }
49
+ let ( :code ) { 429 }
50
+
51
+ it 'should parse out a retry-after header if present' do
52
+ begin
53
+ dummy_class . throw_http_exception! ( code , env )
54
+ rescue Bigcommerce ::TooManyRequests => e
55
+ expect ( e . response_headers [ :retry_after ] ) . to eq 1
56
+ end
57
+ end
58
+ end
59
+
46
60
context 'when we get a string body' do
47
61
let ( :body ) { 'Unauthorized' }
48
62
let ( :code ) { 401 }
You can’t perform that action at this time.
0 commit comments