grac 2.2.2 → 2.3.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/grac.rb +2 -2
- data/lib/grac/client.rb +25 -9
- data/lib/grac/exception.rb +21 -0
- data/lib/grac/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: c4258aeb15110d2f08abd1deecca0f6564d7fdf8
|
4
|
+
data.tar.gz: 539a32d74b6ee5af8a338e23a13e52bc0cf6c8dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c07949577cc3d0afd62a0fe6c78893e1077399d6c25385253b712114201c7d2d71af2dd2c6b04ca014d0cb900407b7e8f6ac60e81051ed6a1ff72d0632832c7
|
7
|
+
data.tar.gz: 1d2f35dd0bafdf139751827345cd87c4d3f11c50d4bf471958e5a40a4033274fe81bc69dc27c109c6af32cf606f3a5b3786eefc178a83592394186ed60236e14
|
data/lib/grac.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative 'grac/version'
|
2
|
+
require_relative 'grac/client'
|
data/lib/grac/client.rb
CHANGED
@@ -126,16 +126,32 @@ module Grac
|
|
126
126
|
return true
|
127
127
|
when 0
|
128
128
|
raise Exception::RequestFailed.new(method, response.effective_url, response.return_message)
|
129
|
-
when 400
|
130
|
-
raise Exception::BadRequest.new(method, response.effective_url, response.parsed_or_raw_body)
|
131
|
-
when 403
|
132
|
-
raise Exception::Forbidden.new(method, response.effective_url, response.parsed_or_raw_body)
|
133
|
-
when 404
|
134
|
-
raise Exception::NotFound.new(method, response.effective_url, response.parsed_or_raw_body)
|
135
|
-
when 409
|
136
|
-
raise Exception::Conflict.new(method, response.effective_url, response.parsed_or_raw_body)
|
137
129
|
else
|
138
|
-
|
130
|
+
begin
|
131
|
+
# The Response class doesn't have enough information to create a proper exception, so
|
132
|
+
# catch its exception and raise a proper one.
|
133
|
+
parsed_body = response.parsed_json
|
134
|
+
rescue Exception::InvalidContent
|
135
|
+
raise Exception::ErrorWithInvalidContent.new(
|
136
|
+
method,
|
137
|
+
response.effective_url,
|
138
|
+
response.code,
|
139
|
+
response.body,
|
140
|
+
'json'
|
141
|
+
)
|
142
|
+
end
|
143
|
+
case response.code
|
144
|
+
when 400
|
145
|
+
raise Exception::BadRequest.new(method, response.effective_url, parsed_body)
|
146
|
+
when 403
|
147
|
+
raise Exception::Forbidden.new(method, response.effective_url, parsed_body)
|
148
|
+
when 404
|
149
|
+
raise Exception::NotFound.new(method, response.effective_url, parsed_body)
|
150
|
+
when 409
|
151
|
+
raise Exception::Conflict.new(method, response.effective_url, parsed_body)
|
152
|
+
else
|
153
|
+
raise Exception::ServiceError.new(method, response.effective_url, parsed_body)
|
154
|
+
end
|
139
155
|
end
|
140
156
|
end
|
141
157
|
|
data/lib/grac/exception.rb
CHANGED
@@ -70,5 +70,26 @@ module Grac
|
|
70
70
|
|
71
71
|
alias_method :to_s, :message
|
72
72
|
end
|
73
|
+
|
74
|
+
class ErrorWithInvalidContent < StandardError
|
75
|
+
def initialize(method, url, status, raw_body, expected_type)
|
76
|
+
@method = (method || "").upcase
|
77
|
+
@url = url
|
78
|
+
@status = status
|
79
|
+
@raw_body = raw_body
|
80
|
+
@expected_type = expected_type
|
81
|
+
end
|
82
|
+
|
83
|
+
def message
|
84
|
+
"#{@method} '#{@url}': Got HTTP #{@status}, failed to parse as '#{@expected_type}'. " \
|
85
|
+
"Raw Body: '#{@raw_body}'"
|
86
|
+
end
|
87
|
+
|
88
|
+
def inspect
|
89
|
+
"#{self.class.name}: #{message}"
|
90
|
+
end
|
91
|
+
|
92
|
+
alias_method :to_s, :message
|
93
|
+
end
|
73
94
|
end
|
74
95
|
end
|
data/lib/grac/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Schoknecht
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|