fb_graph 2.7.3 → 2.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/fb_graph/auth.rb +2 -2
- data/lib/fb_graph/exception.rb +86 -83
- data/lib/fb_graph/node.rb +1 -1
- data/spec/fb_graph/exception_spec.rb +229 -166
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f394a8d8b3ac2e339d04d51b5cd3cb8f84326acd
|
4
|
+
data.tar.gz: 3ec54684dd935ae3f7f86c2cb7a040e4ffb6c5d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 738a30bc38006244ac3aeeb59498e7a9565d4ad87004288ff344249df374e78f7f02ff54867c5b06012444cf60c049c29dbfc989cf029911fe9d43e83e181781
|
7
|
+
data.tar.gz: 347d5b4d682d68145126f151374c497836853c4261d65b9ff2be2ab90f29024cb75ab76712dd4d236dbaba02846f705a3cd64529de3cdbb3c3685c6672edbfd4
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.7.
|
1
|
+
2.7.4
|
data/lib/fb_graph/auth.rb
CHANGED
@@ -56,7 +56,7 @@ module FbGraph
|
|
56
56
|
self.access_token = client.access_token! :client_auth_body
|
57
57
|
self
|
58
58
|
rescue Rack::OAuth2::Client::Error => e
|
59
|
-
Exception.
|
59
|
+
Exception.handle_response e.status, e.message
|
60
60
|
end
|
61
61
|
|
62
62
|
private
|
@@ -69,7 +69,7 @@ module FbGraph
|
|
69
69
|
self.user = User.new(data[:user_id], :access_token => access_token)
|
70
70
|
self
|
71
71
|
rescue Rack::OAuth2::Client::Error => e
|
72
|
-
Exception.
|
72
|
+
Exception.handle_response e.status, e.message
|
73
73
|
end
|
74
74
|
|
75
75
|
def build_access_token(data)
|
data/lib/fb_graph/exception.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module FbGraph
|
2
2
|
class Exception < StandardError
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :status, :type, :error_code, :error_subcode
|
4
|
+
alias_method :code, :status
|
4
5
|
|
5
6
|
ERROR_HEADER_MATCHERS = {
|
6
7
|
/not_found/ => "NotFound",
|
@@ -20,121 +21,123 @@ module FbGraph
|
|
20
21
|
/QueryDuplicateKeyException/ => "QueryDuplicateKey"
|
21
22
|
}
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
class << self
|
25
|
+
def handle_structured_response(status, details, headers)
|
26
|
+
if (error = details[:error])
|
27
|
+
klass = klass_for_header(headers, error) || klass_for_structured_body(error)
|
28
|
+
message = [
|
29
|
+
error[:type] || 'unknown error type',
|
30
|
+
error[:message] || 'unknown error message'
|
31
|
+
].join(' :: ')
|
32
|
+
if klass
|
33
|
+
raise klass.new(message, details)
|
34
|
+
else
|
35
|
+
handle_response status, message, details
|
36
|
+
end
|
37
|
+
else
|
38
|
+
message = [
|
39
|
+
details[:error_code] || 'unknown error_code',
|
40
|
+
details[:error_msg] || 'unknown error_msg'
|
41
|
+
].compact.join(' :: ')
|
42
|
+
handle_response status, message, details
|
43
|
+
end
|
30
44
|
end
|
31
45
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end.to_a.flatten.second
|
39
|
-
if www_authenticate
|
40
|
-
# Session expiration/invalidation is very common. Check for that first.
|
41
|
-
if www_authenticate =~ /invalid_token/ && response[:error][:message] =~ /session has been invalidated/
|
42
|
-
raise InvalidSession.new("#{response[:error][:type]} :: #{response[:error][:message]}")
|
46
|
+
def handle_response(status, message, details = {})
|
47
|
+
klass = klass_for_status status
|
48
|
+
exception = if klass
|
49
|
+
klass.new message, details
|
50
|
+
else
|
51
|
+
Exception.new status, message, details
|
43
52
|
end
|
53
|
+
raise exception
|
54
|
+
end
|
44
55
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
56
|
+
def klass_for_status(status)
|
57
|
+
case status
|
58
|
+
when 400
|
59
|
+
BadRequest
|
60
|
+
when 401
|
61
|
+
Unauthorized
|
62
|
+
when 404
|
63
|
+
NotFound
|
64
|
+
when 500
|
65
|
+
InternalServerError
|
50
66
|
end
|
51
67
|
end
|
52
68
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
ERROR_EXCEPTION_MATCHERS.keys.each do |matcher|
|
60
|
-
exception_class = FbGraph::const_get(ERROR_EXCEPTION_MATCHERS[matcher]) if matcher =~ response[:error][:message]
|
61
|
-
end
|
62
|
-
if exception_class
|
63
|
-
raise exception_class.new("#{response[:error][:type]} :: #{response[:error][:message]}")
|
69
|
+
def klass_for_header(headers, error)
|
70
|
+
key, value = headers.detect do |name, value|
|
71
|
+
name.upcase == "WWW-Authenticate".upcase
|
72
|
+
end || return
|
73
|
+
if value =~ /invalid_token/ && error[:message] =~ /session has been invalidated/
|
74
|
+
InvalidSession
|
64
75
|
else
|
65
|
-
|
76
|
+
matched, klass_name = ERROR_HEADER_MATCHERS.detect do |matcher, klass_name|
|
77
|
+
matcher =~ value
|
78
|
+
end || return
|
79
|
+
FbGraph::const_get klass_name
|
66
80
|
end
|
67
81
|
end
|
68
|
-
end
|
69
82
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
83
|
+
def klass_for_structured_body(error)
|
84
|
+
case error[:type]
|
85
|
+
when /OAuth/
|
86
|
+
Unauthorized
|
87
|
+
else
|
88
|
+
matched, klass_name = ERROR_EXCEPTION_MATCHERS.detect do |matcher, klass_name|
|
89
|
+
matcher =~ error[:message]
|
90
|
+
end || return
|
91
|
+
FbGraph::const_get klass_name
|
92
|
+
end
|
78
93
|
end
|
79
|
-
raise exception
|
80
94
|
end
|
81
95
|
|
82
|
-
def initialize(
|
83
|
-
@
|
84
|
-
if
|
85
|
-
|
86
|
-
|
87
|
-
@
|
96
|
+
def initialize(status, message, details = {})
|
97
|
+
@status = status
|
98
|
+
if (error = details.try(:[], :error))
|
99
|
+
@type = error[:type]
|
100
|
+
@error_code = error[:code]
|
101
|
+
@error_subcode = error[:error_subcode]
|
88
102
|
end
|
89
103
|
super message
|
90
104
|
end
|
91
105
|
end
|
92
106
|
|
93
107
|
class BadRequest < Exception
|
94
|
-
def initialize(message,
|
95
|
-
super 400, message,
|
108
|
+
def initialize(message, details = {})
|
109
|
+
super 400, message, details
|
96
110
|
end
|
97
111
|
end
|
98
112
|
|
99
113
|
class Unauthorized < Exception
|
100
|
-
def initialize(message,
|
101
|
-
super 401, message,
|
114
|
+
def initialize(message, details = {})
|
115
|
+
super 401, message, details
|
102
116
|
end
|
103
117
|
end
|
104
118
|
|
105
119
|
class NotFound < Exception
|
106
|
-
def initialize(message,
|
107
|
-
super 404, message,
|
120
|
+
def initialize(message, details = {})
|
121
|
+
super 404, message, details
|
108
122
|
end
|
109
123
|
end
|
110
124
|
|
111
125
|
class InternalServerError < Exception
|
112
|
-
def initialize(message,
|
113
|
-
super 500, message,
|
126
|
+
def initialize(message, details = {})
|
127
|
+
super 500, message, details
|
114
128
|
end
|
115
129
|
end
|
116
130
|
|
117
|
-
class InvalidToken
|
118
|
-
|
119
|
-
class
|
120
|
-
|
121
|
-
class
|
122
|
-
|
123
|
-
class
|
124
|
-
|
125
|
-
class QueryLockTimeout < InternalServerError; end
|
126
|
-
|
127
|
-
class TargetingSpecNotSaved < InternalServerError; end
|
128
|
-
|
129
|
-
class AdgroupFetchFailure < InternalServerError; end
|
130
|
-
|
131
|
-
class OpenProcessFailure < InternalServerError; end
|
132
|
-
|
131
|
+
class InvalidToken < Unauthorized; end
|
132
|
+
class InvalidSession < InvalidToken; end
|
133
|
+
class InvalidRequest < BadRequest; end
|
134
|
+
class CreativeNotSaved < InternalServerError; end
|
135
|
+
class QueryLockTimeout < InternalServerError; end
|
136
|
+
class TargetingSpecNotSaved < InternalServerError; end
|
137
|
+
class AdgroupFetchFailure < InternalServerError; end
|
138
|
+
class OpenProcessFailure < InternalServerError; end
|
133
139
|
class TransactionCommitFailure < InternalServerError; end
|
134
|
-
|
135
|
-
class
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
class QueryDuplicateKey < InternalServerError; end
|
140
|
-
end
|
140
|
+
class QueryError < InternalServerError; end
|
141
|
+
class QueryConnection < InternalServerError; end
|
142
|
+
class QueryDuplicateKey < InternalServerError; end
|
143
|
+
end
|
data/lib/fb_graph/node.rb
CHANGED
@@ -150,7 +150,7 @@ module FbGraph
|
|
150
150
|
if (200...300).include?(response.status)
|
151
151
|
_response_
|
152
152
|
else
|
153
|
-
Exception.
|
153
|
+
Exception.handle_structured_response(response.status, _response_, response.headers)
|
154
154
|
end
|
155
155
|
end
|
156
156
|
rescue MultiJson::DecodeError
|
@@ -7,16 +7,19 @@ describe FbGraph::Exception do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
context 'when response body is given' do
|
10
|
-
it 'should setup
|
10
|
+
it 'should setup type, error code, and subcode from error' do
|
11
11
|
err = FbGraph::Exception.new(400, 'This is the original message', {
|
12
12
|
:error => {
|
13
13
|
:type => 'SomeError',
|
14
|
-
:message => 'This is the error message'
|
14
|
+
:message => 'This is the error message',
|
15
|
+
:code => 190,
|
16
|
+
:error_subcode => 460
|
15
17
|
}
|
16
|
-
}
|
18
|
+
})
|
17
19
|
err.code.should == 400
|
18
20
|
err.type.should == 'SomeError'
|
19
|
-
err.
|
21
|
+
err.error_code.should == 190
|
22
|
+
err.error_subcode.should == 460
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
@@ -28,157 +31,189 @@ describe FbGraph::Exception do
|
|
28
31
|
err.message.should == 'This is the original message'
|
29
32
|
end
|
30
33
|
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe FbGraph::BadRequest do
|
34
|
-
it 'should have 400 status code' do
|
35
|
-
err = FbGraph::BadRequest.new 'Bad Request'
|
36
|
-
err.code.should == 400
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe FbGraph::Unauthorized do
|
41
|
-
it 'should have 401 status code' do
|
42
|
-
err = FbGraph::Unauthorized.new 'Unauthorized'
|
43
|
-
err.code.should == 401
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe FbGraph::NotFound do
|
48
|
-
it 'should have 404 status code' do
|
49
|
-
err = FbGraph::NotFound.new 'Not Found'
|
50
|
-
err.code.should == 404
|
51
|
-
end
|
52
|
-
end
|
53
34
|
|
54
|
-
describe
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
35
|
+
describe ".handle_structured_response" do
|
36
|
+
context "with WWW-Authenticate header" do
|
37
|
+
context "when token expired" do
|
38
|
+
let(:details) do
|
39
|
+
{
|
40
|
+
:error => {
|
41
|
+
:message => "Error validating access token: The session has been invalidated because the user has changed the password.",
|
42
|
+
:type => "OAuthException"
|
43
|
+
}
|
62
44
|
}
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
45
|
+
end
|
46
|
+
let(:headers) do
|
47
|
+
{
|
48
|
+
"WWW-Authenticate" => 'OAuth "Facebook Platform" "invalid_token" "Error validating access token: The session has been invalidated because the user has changed the password.'
|
49
|
+
}
|
50
|
+
end
|
70
51
|
|
71
|
-
|
72
|
-
|
52
|
+
it do
|
53
|
+
expect do
|
54
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
55
|
+
end.to raise_exception FbGraph::InvalidSession
|
56
|
+
end
|
73
57
|
end
|
74
|
-
end
|
75
58
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
59
|
+
context "when token invalid" do
|
60
|
+
let(:details) do
|
61
|
+
{
|
62
|
+
:error => {
|
63
|
+
:message => 'Invalid OAuth access token.',
|
64
|
+
:type => "OAuthException"
|
65
|
+
}
|
82
66
|
}
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
67
|
+
end
|
68
|
+
let(:headers) do
|
69
|
+
{
|
70
|
+
"WWW-Authenticate" => 'OAuth "Facebook Platform" "invalid_token" "Invalid OAuth access token."'
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
it do
|
75
|
+
expect do
|
76
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
77
|
+
end.to raise_exception FbGraph::InvalidToken
|
78
|
+
end
|
79
|
+
|
80
|
+
context "with a variant capitalization of the header" do
|
81
|
+
let(:headers) do
|
82
|
+
{
|
83
|
+
"Www-Authenticate" => 'OAuth "Facebook Platform" "invalid_token" "Invalid OAuth access token."'
|
84
|
+
}
|
85
|
+
end
|
90
86
|
|
91
|
-
|
92
|
-
|
87
|
+
it do
|
88
|
+
expect do
|
89
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
90
|
+
end.to raise_exception FbGraph::InvalidToken
|
91
|
+
end
|
92
|
+
end
|
93
93
|
end
|
94
94
|
|
95
|
-
context "with
|
95
|
+
context "with an invalid request" do
|
96
|
+
let(:details) do
|
97
|
+
{
|
98
|
+
:error => {
|
99
|
+
:message => '(#100) Must include the \"campaign_id\" index',
|
100
|
+
:type => "OAuthException"
|
101
|
+
}
|
102
|
+
}
|
103
|
+
end
|
96
104
|
let(:headers) do
|
97
105
|
{
|
98
|
-
"
|
106
|
+
"WWW-Authenticate" =>'OAuth "Facebook Platform" "invalid_request" "(#100) Must include the \"campaign_id\" index"'
|
99
107
|
}
|
100
108
|
end
|
101
109
|
|
102
|
-
it
|
103
|
-
|
110
|
+
it do
|
111
|
+
expect do
|
112
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
113
|
+
end.to raise_exception FbGraph::InvalidRequest
|
104
114
|
end
|
105
115
|
end
|
106
|
-
end
|
107
116
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
117
|
+
context "to an an alias that does not exist" do
|
118
|
+
let(:details) do
|
119
|
+
{
|
120
|
+
:error => {
|
121
|
+
:message => '(#803) Some of the aliases you requested do not exist: test',
|
122
|
+
:type => "OAuthException"
|
123
|
+
}
|
114
124
|
}
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
125
|
+
end
|
126
|
+
let(:headers) do
|
127
|
+
{
|
128
|
+
"WWW-Authenticate" =>'OAuth "Facebook Platform" "not_found" "(#803) Some of the aliases you requested do not exist: test"'
|
129
|
+
}
|
130
|
+
end
|
122
131
|
|
123
|
-
|
124
|
-
|
132
|
+
it do
|
133
|
+
expect do
|
134
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
135
|
+
end.to raise_exception FbGraph::NotFound
|
136
|
+
end
|
125
137
|
end
|
126
138
|
end
|
127
139
|
|
128
|
-
context "
|
129
|
-
let(:parsed_response) do
|
130
|
-
{
|
131
|
-
:error => {
|
132
|
-
:message => '(#803) Some of the aliases you requested do not exist: test',
|
133
|
-
:type => "OAuthException"
|
134
|
-
}
|
135
|
-
}
|
136
|
-
end
|
140
|
+
context "without the WWW-Authenticate header" do
|
137
141
|
let(:headers) do
|
138
|
-
{
|
139
|
-
"WWW-Authenticate" =>'OAuth "Facebook Platform" "not_found" "(#803) Some of the aliases you requested do not exist: test"'
|
140
|
-
}
|
142
|
+
{}
|
141
143
|
end
|
142
144
|
|
143
|
-
|
144
|
-
|
145
|
+
context "with an OAuthException" do
|
146
|
+
let(:details) do
|
147
|
+
{
|
148
|
+
:error => {
|
149
|
+
:message => 'Some kind of OAuthException',
|
150
|
+
:type => "OAuthException"
|
151
|
+
}
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
it do
|
156
|
+
expect do
|
157
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
158
|
+
end.to raise_exception FbGraph::Unauthorized
|
159
|
+
end
|
145
160
|
end
|
146
|
-
end
|
147
|
-
end
|
148
161
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
162
|
+
context "with a general exception" do
|
163
|
+
let(:details) do
|
164
|
+
{
|
165
|
+
:error => {
|
166
|
+
:message => 'Some kind of Exception',
|
167
|
+
:type => "Exception"
|
168
|
+
}
|
156
169
|
}
|
157
|
-
|
158
|
-
end
|
170
|
+
end
|
159
171
|
|
160
|
-
|
161
|
-
|
172
|
+
{
|
173
|
+
400 => FbGraph::BadRequest,
|
174
|
+
401 => FbGraph::Unauthorized,
|
175
|
+
404 => FbGraph::NotFound,
|
176
|
+
500 => FbGraph::InternalServerError,
|
177
|
+
999 => FbGraph::Exception
|
178
|
+
}.each do |status, exception_klass|
|
179
|
+
context "when status=#{status}" do
|
180
|
+
it do
|
181
|
+
expect do
|
182
|
+
FbGraph::Exception.handle_structured_response(status, details, headers)
|
183
|
+
end.to raise_exception exception_klass
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
162
187
|
end
|
163
|
-
end
|
164
188
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
:
|
170
|
-
:type => "Exception"
|
189
|
+
context "with an unknown exception" do
|
190
|
+
let(:details) do
|
191
|
+
{
|
192
|
+
:error_code => 1,
|
193
|
+
:error_msg => "An unknown error occurred."
|
171
194
|
}
|
172
|
-
|
173
|
-
end
|
195
|
+
end
|
174
196
|
|
175
|
-
|
176
|
-
|
197
|
+
{
|
198
|
+
400 => FbGraph::BadRequest,
|
199
|
+
401 => FbGraph::Unauthorized,
|
200
|
+
404 => FbGraph::NotFound,
|
201
|
+
500 => FbGraph::InternalServerError,
|
202
|
+
999 => FbGraph::Exception
|
203
|
+
}.each do |status, exception_klass|
|
204
|
+
context "when status=#{status}" do
|
205
|
+
it do
|
206
|
+
expect do
|
207
|
+
FbGraph::Exception.handle_structured_response(status, details, headers)
|
208
|
+
end.to raise_exception exception_klass
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
177
212
|
end
|
178
213
|
|
179
|
-
|
214
|
+
describe "Ads API Exception" do
|
180
215
|
context "of Could not save creative" do
|
181
|
-
let(:
|
216
|
+
let(:details) do
|
182
217
|
{
|
183
218
|
:error => {
|
184
219
|
:message => 'Could not save creative',
|
@@ -187,88 +222,102 @@ describe FbGraph::Exception, ".handle_httpclient_error" do
|
|
187
222
|
}
|
188
223
|
end
|
189
224
|
|
190
|
-
it
|
191
|
-
|
225
|
+
it do
|
226
|
+
expect do
|
227
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
228
|
+
end.to raise_exception FbGraph::CreativeNotSaved
|
192
229
|
end
|
193
230
|
end
|
194
231
|
|
195
|
-
context "of
|
196
|
-
let(:
|
232
|
+
context "of Could not create targeting spec" do
|
233
|
+
let(:details) do
|
197
234
|
{
|
198
235
|
:error => {
|
199
|
-
:message => '
|
236
|
+
:message => 'Could not create targeting spec',
|
200
237
|
:type => "Exception"
|
201
238
|
}
|
202
239
|
}
|
203
240
|
end
|
204
241
|
|
205
|
-
it
|
206
|
-
|
242
|
+
it do
|
243
|
+
expect do
|
244
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
245
|
+
end.to raise_exception FbGraph::TargetingSpecNotSaved
|
207
246
|
end
|
208
247
|
end
|
209
248
|
|
210
|
-
context "of Could not
|
211
|
-
let(:
|
249
|
+
context "of Could not fetch adgroups" do
|
250
|
+
let(:details) do
|
212
251
|
{
|
213
252
|
:error => {
|
214
|
-
:message => 'Could not
|
253
|
+
:message => 'Could not fetch adgroups',
|
215
254
|
:type => "Exception"
|
216
255
|
}
|
217
256
|
}
|
218
257
|
end
|
219
258
|
|
220
|
-
it
|
221
|
-
|
259
|
+
it do
|
260
|
+
expect do
|
261
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
262
|
+
end.to raise_exception FbGraph::AdgroupFetchFailure
|
222
263
|
end
|
223
264
|
end
|
224
265
|
|
225
|
-
context "of
|
226
|
-
let(:
|
266
|
+
context "of Failed to open process" do
|
267
|
+
let(:details) do
|
227
268
|
{
|
228
269
|
:error => {
|
229
|
-
:message => '
|
270
|
+
:message => 'Failed to open process',
|
230
271
|
:type => "Exception"
|
231
272
|
}
|
232
273
|
}
|
233
274
|
end
|
234
275
|
|
235
|
-
it
|
236
|
-
|
276
|
+
it do
|
277
|
+
expect do
|
278
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
279
|
+
end.to raise_exception FbGraph::OpenProcessFailure
|
237
280
|
end
|
238
281
|
end
|
239
282
|
|
240
|
-
context "of
|
241
|
-
let(:
|
283
|
+
context "of Could not commit transaction" do
|
284
|
+
let(:details) do
|
242
285
|
{
|
243
286
|
:error => {
|
244
|
-
:message => '
|
287
|
+
:message => 'Could not commit transaction',
|
245
288
|
:type => "Exception"
|
246
289
|
}
|
247
290
|
}
|
248
291
|
end
|
249
292
|
|
250
|
-
it
|
251
|
-
|
293
|
+
it do
|
294
|
+
expect do
|
295
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
296
|
+
end.to raise_exception FbGraph::TransactionCommitFailure
|
252
297
|
end
|
253
298
|
end
|
299
|
+
end
|
254
300
|
|
255
|
-
|
256
|
-
|
301
|
+
describe 'FQL Exceptions' do
|
302
|
+
context "of QueryLockTimeout" do
|
303
|
+
let(:details) do
|
257
304
|
{
|
258
305
|
:error => {
|
259
|
-
:message => '
|
306
|
+
:message => 'QueryLockTimeoutException',
|
260
307
|
:type => "Exception"
|
261
308
|
}
|
262
309
|
}
|
263
310
|
end
|
264
311
|
|
265
|
-
it
|
266
|
-
|
312
|
+
it do
|
313
|
+
expect do
|
314
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
315
|
+
end.to raise_exception FbGraph::QueryLockTimeout
|
267
316
|
end
|
268
317
|
end
|
269
318
|
|
270
319
|
context "of QueryErrorException" do
|
271
|
-
let(:
|
320
|
+
let(:details) do
|
272
321
|
{
|
273
322
|
:error => {
|
274
323
|
:message => 'DB Error: QueryErrorException',
|
@@ -277,13 +326,15 @@ describe FbGraph::Exception, ".handle_httpclient_error" do
|
|
277
326
|
}
|
278
327
|
end
|
279
328
|
|
280
|
-
it
|
281
|
-
|
329
|
+
it do
|
330
|
+
expect do
|
331
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
332
|
+
end.to raise_exception FbGraph::QueryError
|
282
333
|
end
|
283
334
|
end
|
284
335
|
|
285
336
|
context "of QueryConnectionException" do
|
286
|
-
let(:
|
337
|
+
let(:details) do
|
287
338
|
{
|
288
339
|
:error => {
|
289
340
|
:message => 'QueryConnectionException',
|
@@ -292,13 +343,15 @@ describe FbGraph::Exception, ".handle_httpclient_error" do
|
|
292
343
|
}
|
293
344
|
end
|
294
345
|
|
295
|
-
it
|
296
|
-
|
346
|
+
it do
|
347
|
+
expect do
|
348
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
349
|
+
end.to raise_exception FbGraph::QueryConnection
|
297
350
|
end
|
298
351
|
end
|
299
352
|
|
300
353
|
context "of QueryDuplicateKeyException" do
|
301
|
-
let(:
|
354
|
+
let(:details) do
|
302
355
|
{
|
303
356
|
:error => {
|
304
357
|
:message => 'QueryDuplicateKeyException',
|
@@ -307,24 +360,34 @@ describe FbGraph::Exception, ".handle_httpclient_error" do
|
|
307
360
|
}
|
308
361
|
end
|
309
362
|
|
310
|
-
it
|
311
|
-
|
363
|
+
it do
|
364
|
+
expect do
|
365
|
+
FbGraph::Exception.handle_structured_response(999, details, headers)
|
366
|
+
end.to raise_exception FbGraph::QueryDuplicateKey
|
312
367
|
end
|
313
368
|
end
|
314
369
|
end
|
315
370
|
end
|
316
|
-
|
317
|
-
|
318
|
-
{
|
319
|
-
:error_code => 1,
|
320
|
-
:error_msg => "An unknown error occurred."
|
321
|
-
}
|
322
|
-
end
|
371
|
+
end
|
372
|
+
end
|
323
373
|
|
324
|
-
|
325
|
-
|
326
|
-
|
374
|
+
describe FbGraph::BadRequest do
|
375
|
+
it 'should have 400 status code' do
|
376
|
+
err = FbGraph::BadRequest.new 'Bad Request'
|
377
|
+
err.code.should == 400
|
378
|
+
end
|
379
|
+
end
|
327
380
|
|
328
|
-
|
381
|
+
describe FbGraph::Unauthorized do
|
382
|
+
it 'should have 401 status code' do
|
383
|
+
err = FbGraph::Unauthorized.new 'Unauthorized'
|
384
|
+
err.code.should == 401
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
describe FbGraph::NotFound do
|
389
|
+
it 'should have 404 status code' do
|
390
|
+
err = FbGraph::NotFound.new 'Not Found'
|
391
|
+
err.code.should == 404
|
329
392
|
end
|
330
393
|
end
|