served 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +11 -6
- data/CHANGELOG.md +5 -0
- data/lib/served/resource/http_errors.rb +35 -60
- data/lib/served/resource/requestable.rb +9 -5
- data/lib/served/serializers/json.rb +2 -0
- data/lib/served/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: f16ed665b06a5042b1acf3658918c48c2dfebabd
|
4
|
+
data.tar.gz: 51638a8ecb500306975a9fb962abeb117c4aa7d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a582540ae2fe53989249f28cd5b0e6cadb81182837dbc6ab4321f9cce2fb939c22c57964158f0e1ab90dc911b0091092535ba07c94da6836948aff9b3a25753
|
7
|
+
data.tar.gz: f74a7473319e02a655a7b9b6a98066905f074eb383273e052d498e634900c288628d5d8d0c26054e6e1a695dca9b0ad3b7c0fca4326e4fb00e738c7a646ba404
|
data/.travis.yml
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.1
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
3
|
+
- 2.1.9
|
4
|
+
- 2.1.10
|
5
|
+
- 2.2.7
|
6
|
+
- 2.3.2
|
7
|
+
- 2.3.4
|
8
|
+
- 2.4.1
|
7
9
|
before_install: gem install bundler -v 1.10.5
|
8
10
|
|
9
11
|
gemfile:
|
@@ -13,5 +15,8 @@ gemfile:
|
|
13
15
|
|
14
16
|
matrix:
|
15
17
|
exclude:
|
16
|
-
-
|
17
|
-
|
18
|
+
- rvm: 2.1.9
|
19
|
+
gemfile: gemfiles/5.0.gemfile
|
20
|
+
- rvm: 2.1.10
|
21
|
+
gemfile: gemfiles/5.0.gemfile
|
22
|
+
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.4.1
|
4
|
+
* update CI to cover latest version so of ruby
|
5
|
+
* Fixes unhandled exception when error response isn't valid JSON
|
6
|
+
* Fix HTTP error handling to all codes are dealt with consistently.
|
7
|
+
|
3
8
|
## 0.4.0
|
4
9
|
* Install rubocop and make everything compliant.
|
5
10
|
* Improve error messaging for inclusion validations.
|
@@ -7,24 +7,20 @@ module Served
|
|
7
7
|
attr_reader :response
|
8
8
|
attr_reader :code
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
raise NotImplementedError
|
13
|
-
end
|
10
|
+
def initialize(code, resource, response)
|
11
|
+
@code = code
|
14
12
|
|
15
|
-
def initialize(resource, response)
|
16
13
|
if resource.serializer.respond_to? :exception
|
17
14
|
serialized = resource.serializer.exception(response.body).symbolize_keys!
|
18
15
|
|
19
16
|
@error = serialized[:error]
|
20
17
|
@message = serialized[:exception]
|
21
18
|
@server_backtrace = serialized[:backtrace]
|
22
|
-
@code = serialized[:code] || serialized[:code] = self.class.code
|
23
19
|
@response = OpenStruct.new(serialized) # TODO: remove in served 1.0, used for backwards compat
|
24
20
|
|
25
21
|
super("An error '#{code} #{message}' occurred while making this request")
|
26
22
|
end
|
27
|
-
super "An error occurred '#{
|
23
|
+
super "An error occurred '#{code}'"
|
28
24
|
end
|
29
25
|
|
30
26
|
def status
|
@@ -32,81 +28,60 @@ module Served
|
|
32
28
|
end
|
33
29
|
end
|
34
30
|
|
35
|
-
#
|
36
|
-
class
|
37
|
-
def self.code
|
38
|
-
301
|
39
|
-
end
|
31
|
+
# 302, 303, 307
|
32
|
+
class Redirection < HttpError
|
40
33
|
end
|
41
34
|
|
42
|
-
#
|
43
|
-
class
|
44
|
-
|
45
|
-
|
46
|
-
|
35
|
+
# 301 Moved Permanently
|
36
|
+
class MovedPermanently < Redirection
|
37
|
+
end
|
38
|
+
|
39
|
+
# 401-499
|
40
|
+
class ClientError < HttpError
|
41
|
+
end
|
42
|
+
|
43
|
+
# 400 Bad Request
|
44
|
+
class BadRequest < ClientError
|
47
45
|
end
|
48
46
|
|
49
47
|
# 401 Unauthorized
|
50
|
-
class Unauthorized <
|
51
|
-
def self.code
|
52
|
-
401
|
53
|
-
end
|
48
|
+
class Unauthorized < ClientError
|
54
49
|
end
|
55
50
|
|
56
51
|
# 403 Forbidden
|
57
|
-
class Forbidden <
|
58
|
-
def self.code
|
59
|
-
403
|
60
|
-
end
|
52
|
+
class Forbidden < ClientError
|
61
53
|
end
|
62
54
|
|
63
|
-
# 404
|
64
|
-
class NotFound <
|
65
|
-
def self.code
|
66
|
-
404
|
67
|
-
end
|
55
|
+
# 404 Not Found
|
56
|
+
class NotFound < ClientError
|
68
57
|
end
|
69
58
|
|
70
|
-
# 405
|
71
|
-
class MethodNotAllowed <
|
72
|
-
def self.code
|
73
|
-
405
|
74
|
-
end
|
59
|
+
# 405 Method Not Allowed
|
60
|
+
class MethodNotAllowed < ClientError
|
75
61
|
end
|
76
62
|
|
77
|
-
# 406
|
78
|
-
class NotAcceptable <
|
79
|
-
def self.code
|
80
|
-
406
|
81
|
-
end
|
63
|
+
# 406 Not Acceptable
|
64
|
+
class NotAcceptable < ClientError
|
82
65
|
end
|
83
66
|
|
84
|
-
# 408
|
85
|
-
class RequestTimeout <
|
86
|
-
def self.code
|
87
|
-
408
|
88
|
-
end
|
67
|
+
# 408 Request Timeout
|
68
|
+
class RequestTimeout < ClientError
|
89
69
|
end
|
90
70
|
|
91
|
-
# 422
|
92
|
-
class UnprocessableEntity <
|
93
|
-
def self.code
|
94
|
-
422
|
95
|
-
end
|
71
|
+
# 422 Unprocessable Entity
|
72
|
+
class UnprocessableEntity < ClientError
|
96
73
|
end
|
97
74
|
|
98
|
-
#
|
99
|
-
class
|
100
|
-
def self.code
|
101
|
-
500
|
102
|
-
end
|
75
|
+
# 5xx Server Error
|
76
|
+
class ServerError < HttpError
|
103
77
|
end
|
104
78
|
|
105
|
-
#
|
106
|
-
class
|
107
|
-
|
108
|
-
|
109
|
-
|
79
|
+
# 500 Internal Server Error
|
80
|
+
class InternalServerError < ServerError
|
81
|
+
end
|
82
|
+
|
83
|
+
# 503 Bad Gateway
|
84
|
+
class BadGateway < ServerError
|
110
85
|
end
|
111
86
|
end
|
112
87
|
end
|
@@ -42,10 +42,12 @@ module Served
|
|
42
42
|
end
|
43
43
|
|
44
44
|
handle((200..201), :load)
|
45
|
-
handle([
|
45
|
+
handle([202, 204]) { attributes }
|
46
46
|
|
47
|
-
# 400 level errors
|
48
47
|
handle(301) { Resource::MovedPermanently }
|
48
|
+
handle([302, 303, 304, 305, 307, 308]) { Resource::Redirection }
|
49
|
+
|
50
|
+
# 400 level errors
|
49
51
|
handle(400) { Resource::BadRequest }
|
50
52
|
handle(401) { Resource::Unauthorized }
|
51
53
|
handle(403) { Resource::Forbidden }
|
@@ -54,16 +56,18 @@ module Served
|
|
54
56
|
handle(406) { Resource::NotAcceptable }
|
55
57
|
handle(408) { Resource::RequestTimeout }
|
56
58
|
handle(422) { Resource::UnprocessableEntity }
|
59
|
+
handle((400..499)) { Resource::ClientError }
|
57
60
|
|
58
61
|
# 500 level errors
|
59
62
|
handle(500) { Resource::InternalServerError }
|
60
63
|
handle(503) { Resource::BadGateway }
|
64
|
+
handle((500..599)) { Resource::ServerError }
|
61
65
|
end
|
62
66
|
|
63
67
|
module ClassMethods
|
64
68
|
def handle_response(response)
|
65
69
|
if raise_on_exceptions
|
66
|
-
handler = handlers
|
70
|
+
handler = handlers.fetch(response.code) { proc { HttpError } }
|
67
71
|
if handler.is_a? Proc
|
68
72
|
result = handler.call(response)
|
69
73
|
else
|
@@ -71,7 +75,7 @@ module Served
|
|
71
75
|
end
|
72
76
|
|
73
77
|
if result.respond_to?(:ancestors) && result.ancestors.include?(HttpError)
|
74
|
-
raise result.new(self, response)
|
78
|
+
raise result.new(response.code, self, response)
|
75
79
|
end
|
76
80
|
result
|
77
81
|
else
|
@@ -90,7 +94,7 @@ module Served
|
|
90
94
|
raise HandlerRequired unless symbol_or_proc || block_given?
|
91
95
|
if code_or_range.is_a?(Range) || code_or_range.is_a?(Array)
|
92
96
|
code_or_range.each do |c|
|
93
|
-
handlers[c] = symbol_or_proc || block
|
97
|
+
handlers[c] = symbol_or_proc || block unless handlers.key?(c)
|
94
98
|
end
|
95
99
|
else
|
96
100
|
handlers[code_or_range] = symbol_or_proc || block
|
data/lib/served/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: served
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarod Reid
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|