lhc 5.0.3 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lhc/error.rb +2 -1
- data/lib/lhc/response.rb +2 -24
- data/lib/lhc/version.rb +1 -1
- data/spec/error/find_spec.rb +3 -2
- data/spec/error/to_s_spec.rb +34 -0
- data/spec/request/error_handling_spec.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a6996ab7562372bd3b44f71dd6fc84485804698
|
4
|
+
data.tar.gz: 1ca24023acb23ac975f44efdabf6ab44428a2b95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e75e7a6f8e4892f28f599e0906a92db5b87570804baec6f32aa7726faeecd371391ad21bda686a0b7814f15b279672ebdc4589cf735aa2b4e5372a109f7286bb
|
7
|
+
data.tar.gz: ec0046316b97ef9eb902bde1d2ec3c6dbe872ea9ff821801168bdbde71d4ba2f3559fdf7d349844276f1cf4166637e1341066927f35c0644e70343c7d8f17527
|
data/lib/lhc/error.rb
CHANGED
@@ -58,7 +58,8 @@ class LHC::Error < StandardError
|
|
58
58
|
debug << [request.method, request.url].map { |str| fix_invalid_encoding(str) }.join(' ')
|
59
59
|
debug << "Options: #{request.options}"
|
60
60
|
debug << "Headers: #{request.headers}"
|
61
|
-
debug << "Response Code: #{response.code}"
|
61
|
+
debug << "Response Code: #{response.code} (#{response.options[:return_code]})"
|
62
|
+
debug << "Repsonse Options: #{response.options}"
|
62
63
|
debug << response.body
|
63
64
|
debug << _message
|
64
65
|
debug.map { |str| fix_invalid_encoding(str) }.join("\n")
|
data/lib/lhc/response.rb
CHANGED
@@ -6,6 +6,8 @@ class LHC::Response
|
|
6
6
|
|
7
7
|
attr_accessor :request, :body_replacement
|
8
8
|
|
9
|
+
delegate :effective_url, :code, :headers, :options, :mock, :success?, to: :raw
|
10
|
+
|
9
11
|
# A response is initalized with the underlying raw response (typhoeus in our case)
|
10
12
|
# and the associated request.
|
11
13
|
def initialize(raw, request)
|
@@ -21,30 +23,10 @@ class LHC::Response
|
|
21
23
|
data[key]
|
22
24
|
end
|
23
25
|
|
24
|
-
def effective_url
|
25
|
-
raw.effective_url
|
26
|
-
end
|
27
|
-
|
28
26
|
def body
|
29
27
|
body_replacement || raw.body
|
30
28
|
end
|
31
29
|
|
32
|
-
def code
|
33
|
-
raw.code
|
34
|
-
end
|
35
|
-
|
36
|
-
def headers
|
37
|
-
raw.headers
|
38
|
-
end
|
39
|
-
|
40
|
-
def options
|
41
|
-
raw.options
|
42
|
-
end
|
43
|
-
|
44
|
-
def mock
|
45
|
-
raw.mock
|
46
|
-
end
|
47
|
-
|
48
30
|
# Provides response time in ms.
|
49
31
|
def time
|
50
32
|
(raw.time || 0) * 1000
|
@@ -54,10 +36,6 @@ class LHC::Response
|
|
54
36
|
raw.timed_out?
|
55
37
|
end
|
56
38
|
|
57
|
-
def success?
|
58
|
-
raw.success?
|
59
|
-
end
|
60
|
-
|
61
39
|
def format
|
62
40
|
return JsonFormat.new if request.nil?
|
63
41
|
request.format
|
data/lib/lhc/version.rb
CHANGED
data/spec/error/find_spec.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC::Error do
|
4
|
-
def response(code)
|
5
|
-
LHC::Response.new(OpenStruct.new(code: code), nil)
|
4
|
+
def response(code, timedout = false)
|
5
|
+
LHC::Response.new(OpenStruct.new(code: code, 'timed_out?' => timedout), nil)
|
6
6
|
end
|
7
7
|
|
8
8
|
context 'find' do
|
9
9
|
it 'finds error class by status code' do
|
10
|
+
expect(LHC::Error.find(response('0', true))).to eq LHC::Timeout
|
10
11
|
expect(LHC::Error.find(response('400'))).to eq LHC::BadRequest
|
11
12
|
expect(LHC::Error.find(response('401'))).to eq LHC::Unauthorized
|
12
13
|
expect(LHC::Error.find(response('402'))).to eq LHC::PaymentRequired
|
data/spec/error/to_s_spec.rb
CHANGED
@@ -40,5 +40,39 @@ describe LHC::Error do
|
|
40
40
|
end
|
41
41
|
# the other cases cannot be tested (for example what happens if the headers contain invalid data)
|
42
42
|
# because the mocking framework triggers the encoding error already
|
43
|
+
|
44
|
+
context 'some mocked response' do
|
45
|
+
let(:request) do
|
46
|
+
double('request',
|
47
|
+
method: 'GET',
|
48
|
+
url: 'http://example.com/sessions',
|
49
|
+
headers: { 'Bearer Token' => "aaaaaaaa-bbbb-cccc-dddd-eeee"},
|
50
|
+
options: { followlocation: true,
|
51
|
+
auth: { bearer: "aaaaaaaa-bbbb-cccc-dddd-eeee"},
|
52
|
+
params: { limit: 20}, url: "http://example.com/sessions" })
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:response) do
|
56
|
+
double('response',
|
57
|
+
request: request,
|
58
|
+
code: 500,
|
59
|
+
options: { return_code: :internal_error, response_headers: "" },
|
60
|
+
body: '{"status":500,"message":"undefined"}')
|
61
|
+
end
|
62
|
+
|
63
|
+
subject { LHC::Error.new('The error message', response) }
|
64
|
+
|
65
|
+
it 'produces correct debug output' do
|
66
|
+
expect(subject.to_s.split("\n")).to eq(<<-MSG.strip_heredoc.split("\n"))
|
67
|
+
GET http://example.com/sessions
|
68
|
+
Options: {:followlocation=>true, :auth=>{:bearer=>"aaaaaaaa-bbbb-cccc-dddd-eeee"}, :params=>{:limit=>20}, :url=>"http://example.com/sessions"}
|
69
|
+
Headers: {"Bearer Token"=>"aaaaaaaa-bbbb-cccc-dddd-eeee"}
|
70
|
+
Response Code: 500 (internal_error)
|
71
|
+
Repsonse Options: {:return_code=>:internal_error, :response_headers=>""}
|
72
|
+
{"status":500,"message":"undefined"}
|
73
|
+
The error message
|
74
|
+
MSG
|
75
|
+
end
|
76
|
+
end
|
43
77
|
end
|
44
78
|
end
|
@@ -14,6 +14,7 @@ describe LHC::Request do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'raises errors for anything but 2XX response codes' do
|
17
|
+
expect_status_code(0) { to_fail_with(LHC::UnknownError) }
|
17
18
|
expect_status_code(400) { to_fail_with(LHC::BadRequest) }
|
18
19
|
expect_status_code(401) { to_fail_with(LHC::Unauthorized) }
|
19
20
|
expect_status_code(402) { to_fail_with(LHC::PaymentRequired) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhc/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -317,7 +317,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
317
317
|
requirements:
|
318
318
|
- Ruby >= 2.0.0
|
319
319
|
rubyforge_project:
|
320
|
-
rubygems_version: 2.
|
320
|
+
rubygems_version: 2.5.2
|
321
321
|
signing_key:
|
322
322
|
specification_version: 4
|
323
323
|
summary: LocalHttpClient
|