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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f12068ff87343f989361daa76d6177e6ce6512b4
4
- data.tar.gz: eb25f5a8ddfb27a92ee5488dd78cfe19433fe530
3
+ metadata.gz: 62d279fb8e9f3dccbe08c75dd759fb92c6d0760f
4
+ data.tar.gz: 6fa59a669252af7ef626608e9572f05f4d7046c7
5
5
  SHA512:
6
- metadata.gz: 28ec670b376dd160323028839e42dc3cb5928a5392fe6c735ee01882d3040e37bec85bff6b55a98c2161c3bbfea618d86a1647de159e643e04df1c79c21ef57c
7
- data.tar.gz: 97331b6793a5c6035994843f7b5dc5c9a8c491558ae3140607b70a0f1b078cd5cec2ec17d0f451fa57229bede0d5e4dbcdd9759f98b6ac2f064dcad8510a47e0
6
+ metadata.gz: 3f0688032cff2a5b11065bc2a59a8789e1c624af4ab79b21e7cfb1ef02f05affdbf529671262eff05ccaedef61ee366ef2c1394bc5fb088130f2d1722038c73f
7
+ data.tar.gz: 696fb2058426f50b5e772969bd219d364d41882c0c267fa3a6e8d8345335380a239dd7048bbce0481393f38c15725d0eacbd44473deaa2377079ea5bfe4d8706
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.6.0
2
+
3
+ - Add error classes for common errors
4
+ - Add error message decoding from server (and pass onto error message)
5
+
1
6
  # 0.5.2
2
7
 
3
8
  - Fix a bug with the `media_types` integration
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trailer_vote-api (0.5.2)
4
+ trailer_vote-api (0.6.0)
5
5
  http (>= 3.3.0, < 4.x)
6
6
  oj (>= 3.6, < 4.x)
7
7
  trailer_vote-media_types (>= 0.6.1, < 1)
@@ -42,18 +42,44 @@ module TrailerVote
42
42
  end
43
43
 
44
44
  def messages
45
- result.status.reason
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 ErrorsResponse, result
82
+ raise ERROR_MAPPING[result.status], result
57
83
  end
58
84
 
59
85
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TrailerVote
4
4
  module Api
5
- VERSION = '0.5.2'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailer_vote-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derk-Jan Karrenbeld