alephant-publisher-request 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 636d57a2d11137dff5db768d01ca82ecb182d16b
4
- data.tar.gz: 967fcecc92c5208f88247ee5b9ea3f32c23336b4
3
+ metadata.gz: 212638793ae63c57e1e7884d4b9734a366e2a87c
4
+ data.tar.gz: d1150ed44ef1be7842248ebb986c29eca9e85e35
5
5
  SHA512:
6
- metadata.gz: 39927e50459406de2270cac19444387d5964d19f51f075268a0cadb8dde2341a1d1dad1656a00d7f444a996b08ed724de89f498a30750a93da83b9d04f1de7e8
7
- data.tar.gz: c56b87f5bbe539d9f3beac9284ba9eb524a02fcec128ce89bb1a2d4ec7f594bccf3e9fb3dee561298230d4f401d21a06492f8b5c01c7f9cb792f322d35b8a88e
6
+ metadata.gz: 14e04aac1d08505fdfceb01d1752eb3f19d390400a0770d6ffa77c80fa414708988554afecafe90f9a70cd0aeb8291da100c9c44bb7b394f4ede71b4daa342f8
7
+ data.tar.gz: 15796375af93d17e6922f02e602819e787ea16d1ae655eab6782eb34dfc9ed6981575d11d8a89557d8ab2db192e9537b7ce2c6fd2ad6501f4a2ce8ecd47e55d8
@@ -42,6 +42,8 @@ module Alephant
42
42
  end
43
43
 
44
44
  response.finish
45
+ rescue InvalidApiStatus => e
46
+ error_response(e, e.status)
45
47
  rescue ApiError, ConnectionFailed => e
46
48
  error_response(e, 502)
47
49
  rescue InvalidComponent => e
@@ -23,8 +23,8 @@ module Alephant
23
23
  def get(uri)
24
24
  before = Time.new
25
25
  response = connection.get(uri)
26
- raise InvalidApiResponse, "Status: #{response.status}" unless response.status == 200
27
26
  logger.metric(:name => "PublisherRequestDataMapperRequestHTTPTime", :unit => 'Seconds', :value => Time.new - before)
27
+ raise InvalidApiStatus, response.status unless response.status == 200
28
28
  JSON::parse(response.body, :symbolize_names => true)
29
29
  rescue Faraday::ConnectionFailed
30
30
  logger.metric(:name => "PublisherRequestDataMapperConnectionFailed", :unit => "Count", :value => 1)
@@ -32,11 +32,13 @@ module Alephant
32
32
  rescue JSON::ParserError
33
33
  logger.metric(:name => "PublisherRequestDataMapperInvalidApiResponse", :unit => "Count", :value => 1)
34
34
  raise InvalidApiResponse, "JSON parsing error: #{response.body}"
35
+ rescue InvalidApiStatus => e
36
+ logger.metric(:name => "PublisherRequestDataMapperInvalidStatus#{e.status}", :unit => "Count", :value => 1)
37
+ raise e
35
38
  rescue StandardError => e
36
39
  logger.metric(:name => "PublisherRequestDataMapperApiError", :unit => "Count", :value => 1)
37
40
  raise ApiError, e.message
38
41
  end
39
-
40
42
  end
41
43
  end
42
44
  end
@@ -9,6 +9,15 @@ module Alephant
9
9
  class InvalidComponentBasePath < InvalidComponent; end
10
10
  class InvalidComponentName < InvalidComponent; end
11
11
  class InvalidComponentClassName < InvalidComponent; end
12
+ class InvalidApiStatus < ApiError
13
+ attr_accessor :status
14
+
15
+ def initialize(status)
16
+ @status = status
17
+ super("Status: #{status}")
18
+ end
19
+
20
+ end
12
21
  end
13
22
  end
14
23
  end
@@ -1,7 +1,7 @@
1
1
  module Alephant
2
2
  module Publisher
3
3
  module Request
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
6
6
  end
7
7
  end
@@ -35,7 +35,19 @@ describe FooMapper do
35
35
  allow(connection).to receive(:get).and_raise(faraday_exception)
36
36
  end
37
37
 
38
- specify { expect{ subject.data }.to raise_error expected_exception }
38
+ specify { expect { subject.data }.to raise_error expected_exception }
39
39
  end
40
+
41
+ context "invalid status code" do
42
+ let (:status_code) { 503 }
43
+ let (:expected_exception) { Alephant::Publisher::Request::InvalidApiStatus }
44
+ before(:each) do
45
+ allow(connection).to receive(:get).and_return(OpenStruct.new(:status => status_code))
46
+ end
47
+
48
+ specify { expect { subject.data }.to raise_error expected_exception }
49
+ end
50
+
51
+
40
52
  end
41
53
  end
@@ -47,14 +47,26 @@ describe Alephant::Publisher::Request do
47
47
  specify { expect(last_response.status).to eq 404 }
48
48
  end
49
49
 
50
+ context "with an invalid status code" do
51
+ let (:status_code) { 503 }
52
+ let (:expected_exception) { Alephant::Publisher::Request::InvalidApiStatus.new(status_code) }
53
+ before(:each) do
54
+ allow(connection).to receive(:get).and_raise expected_exception
55
+ get "/component/#{component_id}"
56
+ end
57
+
58
+ specify { expect(last_response.status).to eq status_code }
59
+ end
60
+
50
61
  context "with an invalid API endpoint" do
62
+ let (:status_code) { 502 }
51
63
  let (:expected_exception) { Alephant::Publisher::Request::InvalidApiResponse }
52
64
  before(:each) do
53
65
  allow(connection).to receive(:get).and_raise expected_exception
54
66
  get "/component/#{component_id}"
55
67
  end
56
68
 
57
- specify { expect(last_response.status).to eq 502 }
69
+ specify { expect(last_response.status).to eq status_code }
58
70
  end
59
71
 
60
72
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-publisher-request
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Integralist
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-08 00:00:00.000000000 Z
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler