lifen 1.0.1 → 1.0.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: f43d79863f669ef8d3c3bd3bc020c906b70bba38
4
- data.tar.gz: bd2d87955f148b20fbb9f2cfb242d4086f0face7
3
+ metadata.gz: 2f5c85c29e8ab9cc7f36987098d50f12a5beb96d
4
+ data.tar.gz: 74e319a77102bbc00630fa6f24acdec72d4ee789
5
5
  SHA512:
6
- metadata.gz: 30a1acc06def39ca6b5525215d0a7920cf9fed8118817bf8ea5793c45e0116d9a7f9cd9d586655233373fe958688f284a39459e652d76d1e84a6942575a5339a
7
- data.tar.gz: 688364f874269d69368f788a5510a50274e9ad66d8c9958098a216e1c3ad15fdd9111448466d8595c5bf21dedbb47dc0ff502324a3de899af141f7a371ef0f98
6
+ metadata.gz: b6c8d52af33bb08e5c3926d8bbee08edbd50e6da9ded2303fe62f5b917e6c85c4e955d9233414f2ea79ab702624ef68589f16fe0c168f7e51aba58d68027ee32
7
+ data.tar.gz: 436d77f9de97847cf494d0336646a98a958ec12333bf9df5eaf7930d965e8b538fbba24da4d3338b4980fa2ba5986ec331756670f88a37b428c806cc96dc19d6
@@ -1,3 +1,8 @@
1
+ 1.0.2
2
+ -----
3
+
4
+ - Error messages contains more information about failing API requests
5
+
1
6
  1.0.1
2
7
  -----
3
8
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lifen (1.0.1)
4
+ lifen (1.0.2)
5
5
  faraday (>= 0.9)
6
6
  inflecto
7
7
  virtus (>= 1.0)
@@ -3,22 +3,26 @@ module Lifen
3
3
 
4
4
  private
5
5
 
6
- def handle_status!(response)
7
- super(response)
6
+ def handle_errors(response, params)
7
+ super(response, params)
8
8
 
9
9
  case response.status
10
10
  when 400
11
- raise Error, "Error 400"
11
+ raise Error, "Error 400, Unknown error, #{response_error(response, params)}"
12
12
  when 401
13
- raise InvalidSecretTokenError
13
+ raise InvalidSecretTokenError, "Error 401, Invalid app bearer, #{response_error(response, params)}"
14
14
  when 403
15
- raise UserAlreadyExistingError
15
+ raise UserAlreadyExistingError, "Error 403, User already existing, #{response_error(response, params)}"
16
16
  when 404
17
- raise Error, "Error 404, Page not found"
17
+ raise Error, "Error 404, Page not found, #{response_error(response, params)}"
18
18
  end
19
19
 
20
20
  end
21
21
 
22
+ def response_error(response, params)
23
+ "App Client, #{super(response, params)}"
24
+ end
25
+
22
26
  def bearer
23
27
  Lifen.configuration.application_access_token
24
28
  end
@@ -14,7 +14,7 @@ module Lifen
14
14
  req.body = JSON.generate(params)
15
15
  end
16
16
 
17
- handle_status!(response)
17
+ handle_errors(response, params)
18
18
 
19
19
  json = JSON.parse response.body
20
20
 
@@ -31,18 +31,19 @@ module Lifen
31
31
 
32
32
  private
33
33
 
34
- def handle_status!(response)
34
+ def handle_errors(response, params)
35
35
  if response.status == 500
36
+
36
37
  json = JSON.parse response.body
37
38
 
38
39
  trace_id = json.fetch("X-B3-TraceId", "unknown")
39
- raise Error, "Error 500, Internal server error (trace ID: #{trace_id})"
40
+
41
+ raise Error, "Error 500, Internal server error (trace ID: #{trace_id}), #{response_error(response, params)}"
40
42
  end
41
43
  end
42
44
 
43
45
  def faraday_client
44
46
  @faraday_client ||= Faraday.new(faraday_options) do |faraday|
45
- faraday.request :url_encoded # form-encode POST params
46
47
  faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
47
48
  end
48
49
  end
@@ -66,6 +67,18 @@ module Lifen
66
67
  def before_request
67
68
  end
68
69
 
70
+ def response_error(response, params)
71
+ "#{response.env.method.upcase} '#{response.env.url}' with params '#{params.inspect}' and bearer '#{trucanted_bearer}'"
72
+ end
73
+
74
+ def trucanted_bearer
75
+ if m = /^(.{24})(.*)$/.match(bearer)
76
+ "#{m[1]}#{"*" * m[2].length}"
77
+ else
78
+ bearer
79
+ end
80
+ end
81
+
69
82
  def bearer
70
83
  raise "A bearer method must be defined"
71
84
  end
@@ -9,20 +9,24 @@ module Lifen
9
9
 
10
10
  private
11
11
 
12
- def handle_status!(response)
13
- super(response)
12
+ def handle_errors(response, params)
13
+ super(response, params)
14
14
 
15
15
  case response.status
16
16
  when 400
17
- raise InvalidParamsError, "Invalid params"
17
+ raise InvalidParamsError, "Error 400, Invalid params, #{response_error(response, params)}"
18
18
  when 401
19
- raise UnauthorizedError, "Token is not valid"
19
+ raise UnauthorizedError, "Error 401, Token is not valid, #{response_error(response, params)}"
20
20
  when 403
21
- raise Error, "Action is forbidden"
21
+ raise Error, "Error 403, Action is forbidden, #{response_error(response, params)}"
22
22
  end
23
23
 
24
24
  end
25
25
 
26
+ def response_error(response, params)
27
+ "User Client, #{super(response, params)}"
28
+ end
29
+
26
30
  def bearer
27
31
  token.value
28
32
  end
@@ -1,3 +1,3 @@
1
1
  module Lifen
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -19,7 +19,7 @@ describe Lifen::Flow do
19
19
  VCR.use_cassette "flows/invalid_token" do
20
20
  user.flows
21
21
  end
22
- }.to raise_error(Lifen::UnauthorizedError)
22
+ }.to raise_error(Lifen::UnauthorizedError, "Error 401, Token is not valid, User Client, GET 'https://develop.lifen.fr/central/api/chats' with params '{}' and bearer 'invalid_token'")
23
23
  end
24
24
 
25
25
  end
@@ -31,7 +31,7 @@ describe Lifen::Flow do
31
31
  VCR.use_cassette "flows/internal_error" do
32
32
  user.flows
33
33
  end
34
- }.to raise_error(Lifen::Error, "Error 500, Internal server error (trace ID: 2e2eac3a7e3fa2)")
34
+ }.to raise_error(Lifen::Error, "Error 500, Internal server error (trace ID: 2e2eac3a7e3fa2), User Client, GET 'https://develop.lifen.fr/central/api/chats' with params '{}' and bearer 'valid_token'")
35
35
  end
36
36
 
37
37
  it 'raises an error (without trace ID)' do
@@ -39,7 +39,7 @@ describe Lifen::Flow do
39
39
  VCR.use_cassette "flows/internal_error_without_trace_id" do
40
40
  user.flows
41
41
  end
42
- }.to raise_error(Lifen::Error, "Error 500, Internal server error (trace ID: unknown)")
42
+ }.to raise_error(Lifen::Error, "Error 500, Internal server error (trace ID: unknown), User Client, GET 'https://develop.lifen.fr/central/api/chats' with params '{}' and bearer 'valid_token'")
43
43
  end
44
44
 
45
45
  end
@@ -122,7 +122,7 @@ describe Lifen::Flow do
122
122
  VCR.use_cassette "flows/attach_users/invalid_flow_uuid" do
123
123
  flow.attach_users(user)
124
124
  end
125
- }.to raise_error(Lifen::InvalidParamsError)
125
+ }.to raise_error(Lifen::InvalidParamsError, "Error 400, Invalid params, User Client, POST 'https://develop.lifen.fr/central/api/chats/invalid-uuid/attach_users?rel=activeUsers' with params '[\"25588996-4ff1-2dbb-9643-eabb809fa654\"]' and bearer 'valid_token'")
126
126
  end
127
127
 
128
128
  end
@@ -141,7 +141,7 @@ describe Lifen::Flow do
141
141
  VCR.use_cassette "flows/attach_users/invalid_user_uuid" do
142
142
  flow.attach_users(invalid_user)
143
143
  end
144
- }.to raise_error(Lifen::InvalidParamsError)
144
+ }.to raise_error(Lifen::InvalidParamsError, "Error 400, Invalid params, User Client, POST 'https://develop.lifen.fr/central/api/chats/11e6be18-7a35-d759-9177-0242ac110002/attach_users?rel=activeUsers' with params '[\"invalid-uuid\"]' and bearer 'valid_token'")
145
145
  end
146
146
  end
147
147
 
@@ -17,7 +17,7 @@ describe Lifen::User do
17
17
  VCR.use_cassette "users/create/missing_fields" do
18
18
  user.create
19
19
  end
20
- }.to raise_error(Lifen::Error)
20
+ }.to raise_error(Lifen::Error, "Error 401, Invalid app bearer, App Client, POST 'https://develop.lifen.fr/authentication/api/register/third_party' with params '{:emailAddress=>nil, :lastName=>nil, :firstName=>\"Marc\"}' and bearer 'valid_application_access******'")
21
21
  end
22
22
  end
23
23
 
@@ -36,7 +36,7 @@ describe Lifen::User do
36
36
  VCR.use_cassette "users/create/invalid_token" do
37
37
  user.create
38
38
  end
39
- }.to raise_error(Lifen::InvalidSecretTokenError)
39
+ }.to raise_error(Lifen::InvalidSecretTokenError, "Error 401, Invalid app bearer, App Client, POST 'https://develop.lifen.fr/authentication/api/register/third_party' with params '{:emailAddress=>\"invalid-key-email@test.tld\", :lastName=>nil, :firstName=>nil}' and bearer 'invalid-secret-key'")
40
40
  end
41
41
  end
42
42
 
@@ -49,7 +49,7 @@ describe Lifen::User do
49
49
  VCR.use_cassette "users/create/existing_user" do
50
50
  user.create
51
51
  end
52
- }.to raise_error(Lifen::UserAlreadyExistingError)
52
+ }.to raise_error(Lifen::UserAlreadyExistingError, "Error 403, User already existing, App Client, POST 'https://develop.lifen.fr/authentication/api/register/third_party' with params '{:emailAddress=>\"existing-user@domain.tld\", :lastName=>\"User\", :firstName=>\"Existing\"}' and bearer 'valid_application_access******'")
53
53
  end
54
54
  end
55
55
 
@@ -80,7 +80,7 @@ describe Lifen::User do
80
80
  VCR.use_cassette "users/token/refresh/invalid_user_uuid" do
81
81
  user.token.refresh
82
82
  end
83
- }.to raise_error(Lifen::Error)
83
+ }.to raise_error(Lifen::Error, "Error 500, Internal server error (trace ID: unknown), App Client, POST 'https://develop.lifen.fr/oauth/admin/third_party/access_token?accountUuid=invalid-user-uuid' with params '{}' and bearer 'valid_application_access******'")
84
84
  end
85
85
  end
86
86
 
@@ -113,7 +113,7 @@ describe Lifen::User do
113
113
  VCR.use_cassette "users/status/refresh/invalid_token" do
114
114
  user.status.refresh
115
115
  end
116
- }.to raise_error(Lifen::Error)
116
+ }.to raise_error(Lifen::Error, "Error 401, Token is not valid, User Client, GET 'https://develop.lifen.fr/central/api/chats/status' with params '{}' and bearer 'invalid_token'")
117
117
  end
118
118
  end
119
119
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Etienne Depaulis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-13 00:00:00.000000000 Z
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler