paypal_client 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paypal_client/errors.rb +44 -22
- data/lib/paypal_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 114fef4fab02f2da43e422615fb0d80edff7bb4e
|
4
|
+
data.tar.gz: 448d08ed8b3025c4f4d14ea93ac36efcc0e03725
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ee81de3aaa594ee3f992ddd196360091d8ba33159a598a808f9500982324e7da878e81e94bab01d9d54a2af1464ba263f097b0dbcfa2ec7616fed79ec9b1e53
|
7
|
+
data.tar.gz: 490d3240ae8197d8d8d2874bfa163a13d9b6f1e66fc3e6097fb738e31409b11499aa3e2ff8c282a2d846255e785b50bf7152180b87b762ec221a04354e94a719
|
data/lib/paypal_client/errors.rb
CHANGED
@@ -1,31 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday_middleware'
|
2
4
|
|
3
5
|
module PaypalClient
|
4
6
|
module Errors
|
5
7
|
class Error < StandardError
|
6
|
-
attr_reader :
|
7
|
-
attr_reader :
|
8
|
-
attr_reader :
|
9
|
-
attr_reader :
|
10
|
-
|
11
|
-
def initialize(
|
12
|
-
@
|
13
|
-
@
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@error_message = @body[:message] if @body.key?(:message)
|
18
|
-
else
|
19
|
-
@error = response.reason_phrase if @error.nil?
|
20
|
-
end
|
8
|
+
attr_reader :code
|
9
|
+
attr_reader :http_body
|
10
|
+
attr_reader :http_status
|
11
|
+
attr_reader :message
|
12
|
+
|
13
|
+
def initialize(message = nil, http_status: nil, http_body: nil, code: nil)
|
14
|
+
@message = message
|
15
|
+
@http_status = http_status
|
16
|
+
@http_body = http_body
|
17
|
+
@code = code
|
18
|
+
|
21
19
|
super(@error)
|
22
20
|
end
|
23
21
|
|
24
22
|
def inspect
|
25
|
-
extra =
|
26
|
-
extra << " status_code: #{
|
27
|
-
extra << " body: #{
|
28
|
-
"#<#{self.class.name}: #{message}#{extra}>"
|
23
|
+
extra = []
|
24
|
+
extra << " status_code: #{http_status}" unless http_status.nil?
|
25
|
+
extra << " body: #{http_body}" unless http_body.nil?
|
26
|
+
"#<#{self.class.name}: #{message}#{extra.join}>"
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
@@ -57,10 +55,34 @@ module PaypalClient
|
|
57
55
|
503 => ServiceUnavailable
|
58
56
|
}.freeze
|
59
57
|
|
58
|
+
ERRORS_WITHOUT_BODY = [404].freeze
|
59
|
+
|
60
60
|
def on_complete(response)
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
status = response[:status].to_i
|
62
|
+
if status >= 400
|
63
|
+
error = ERROR_MAP.key?(status) ? ERROR_MAP[status] : Error
|
64
|
+
|
65
|
+
body = response.body
|
66
|
+
raise error.new(get_error_message(response), code: get_error_code(response), http_status: status, http_body: body)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def get_error_message(response)
|
73
|
+
body = response.body
|
74
|
+
return body[:message] if body.is_a?(Hash) && body.key?(:message)
|
75
|
+
return body[:error_description] if body.is_a?(Hash) && body.key?(:error_description)
|
76
|
+
|
77
|
+
'Something went wrong'
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_error_code(response)
|
81
|
+
body = response.body
|
82
|
+
return body[:name] if body.is_a?(Hash) && body.key?(:name)
|
83
|
+
return body[:error] if body.is_a?(Hash) && body.key?(:error)
|
84
|
+
|
85
|
+
response.status.to_s
|
64
86
|
end
|
65
87
|
end
|
66
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paypal_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis van der Vliet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|