trailer_vote-api 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/lib/trailer_vote/api/errors.rb +28 -2
- data/lib/trailer_vote/api/version.rb +1 -1
- 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: 62d279fb8e9f3dccbe08c75dd759fb92c6d0760f
|
4
|
+
data.tar.gz: 6fa59a669252af7ef626608e9572f05f4d7046c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f0688032cff2a5b11065bc2a59a8789e1c624af4ab79b21e7cfb1ef02f05affdbf529671262eff05ccaedef61ee366ef2c1394bc5fb088130f2d1722038c73f
|
7
|
+
data.tar.gz: 696fb2058426f50b5e772969bd219d364d41882c0c267fa3a6e8d8345335380a239dd7048bbce0481393f38c15725d0eacbd44473deaa2377079ea5bfe4d8706
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -42,18 +42,44 @@ module TrailerVote
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def messages
|
45
|
-
|
45
|
+
data['errors'].map { |error| error['message'] }.join(', ')
|
46
46
|
end
|
47
47
|
|
48
48
|
def data
|
49
49
|
@data ||= TrailerVote::Api.decode(result)
|
50
|
+
rescue DecodeError
|
51
|
+
# noinspection RubyStringKeysInHashInspection
|
52
|
+
@data = { 'errors' => [{ 'message': result.status.reason }] }
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
56
|
+
class ClientError < ErrorsResponse; end
|
57
|
+
class BadRequest < ClientError; end
|
58
|
+
class Unauthorized < ClientError; end
|
59
|
+
class Forbidden < ClientError; end
|
60
|
+
class NotFound < ClientError; end
|
61
|
+
class Conflict < ClientError; end
|
62
|
+
class Gone < ClientError; end
|
63
|
+
class PreconditionFailed < ClientError; end
|
64
|
+
class TooManyRequests < ClientError; end
|
65
|
+
|
66
|
+
class ServerError < ErrorsResponse; end
|
67
|
+
|
68
|
+
ERROR_MAPPING = Hash.new { |_, key| key < 500 ? ClientError : ServerError }.merge(
|
69
|
+
400 => BadRequest,
|
70
|
+
401 => Unauthorized,
|
71
|
+
403 => Forbidden,
|
72
|
+
404 => NotFound,
|
73
|
+
409 => Conflict,
|
74
|
+
410 => Gone,
|
75
|
+
412 => PreconditionFailed,
|
76
|
+
429 => TooManyRequests
|
77
|
+
).freeze
|
78
|
+
|
53
79
|
module_function
|
54
80
|
|
55
81
|
def raise_error(result)
|
56
|
-
raise
|
82
|
+
raise ERROR_MAPPING[result.status], result
|
57
83
|
end
|
58
84
|
|
59
85
|
end
|