white_noise 1.0.1 → 1.1.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
- SHA1:
3
- metadata.gz: 79bc1a55a2f512f8b236510c50868a5ca0076320
4
- data.tar.gz: 46547d86c770d4d1bce3f5db20cee478fd7ec5cd
2
+ SHA256:
3
+ metadata.gz: 21fb66b0a6a90391211e78936e2728b55f7f6b1d20fc7fc8a8e3ebe1e2deda9e
4
+ data.tar.gz: c425d74ed580041961efd908205a5cce5f3022e4d6cf514daba486085c47a1fa
5
5
  SHA512:
6
- metadata.gz: 2ca565139cbba52b2a2f4c5f78354e92e0aa17a47e7b8358b1906880b69f9d9695d701b9b4646271d6bdb3a98cc13385ecbb34fa23e501b43dcd698ca6531e3b
7
- data.tar.gz: d3d067a315b7f1892b6db5d12f37838d19ef6c766311772f9f860205589918ebebfede1add03dee2fc9a2e6ae69de384de3605ca3021329ebf532382981c6c42
6
+ metadata.gz: f32097f81b7480bac71a0d558fe3e82635487a5a9c9c72faf433612f0b0d492d6e389cd84b3c27597b1ceba505993fb25fac0ffb659f2b6c46601bc920950982
7
+ data.tar.gz: 1fe0facb00afc93581cf134d6f1ff9a7aa183d5f069ea45ba230b77fafb8a228866ef80b90315b306f299c71e9f0983c7150b57ef5e4d3989053caf3a3c91320
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- white_noise (1.0.1)
4
+ white_noise (1.1.0)
5
5
  actionpack
6
6
  active_model_serializers (>= 0.10.0.rc4, < 0.11.0)
7
7
  activesupport
@@ -1,4 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object/try'
4
+
2
5
  module Noise
3
6
  # Determines how to render exception
4
7
  #
@@ -26,7 +29,7 @@ module Noise
26
29
  #
27
30
  # def code
28
31
  # if error.is_a?(PublicError)
29
- # error.message_id
32
+ # error.code
30
33
  # else
31
34
  # :internal_server_error
32
35
  # end
@@ -37,12 +40,12 @@ module Noise
37
40
  # @param responder [ExceptionResponder]
38
41
  # @return [String] error representation
39
42
  def render(responder)
40
- ActiveModel::SerializableResource.new(
43
+ ActiveModelSerializers::SerializableResource.new(
41
44
  Array(error),
42
45
  each_serializer: error_serializer,
43
46
  adapter: :json,
44
47
  root: 'errors',
45
- meta: { 'status' => responder.status_code },
48
+ meta: { 'status' => responder.status_code }.merge(error.try(:meta_hash) || {}),
46
49
  scope: { http_status: responder.status_code, id: error_id },
47
50
  ).as_json.to_json
48
51
  end
@@ -10,17 +10,17 @@ module Noise
10
10
  # Base class for all api level errors
11
11
  #
12
12
  class PublicError < StandardError
13
- attr_reader :message_id
13
+ attr_reader :code
14
14
  attr_reader :options
15
15
 
16
- # @overload new(message_id, message)
17
- # Instantiate error with given message_id and message
18
- # @param message_id [Symbol]
16
+ # @overload new(code, message)
17
+ # Instantiate error with given code and message
18
+ # @param code [Symbol]
19
19
  # @param message_or_options [String]
20
- # @overload new(message_id, options)
21
- # Instantiate error with given message_id and options.
20
+ # @overload new(code, options)
21
+ # Instantiate error with given code and options.
22
22
  # Options would be passed to I18n key
23
- # @param message_id [Symbol]
23
+ # @param code [Symbol]
24
24
  # @param message_or_options [Hash{Symbol => any}]
25
25
  # @example
26
26
  # Given the following I18n key exists:
@@ -31,8 +31,8 @@ module Noise
31
31
  # To render error with this message:
32
32
  # PublicError.new(:unknown_fields, fields: 'nickname, phone')
33
33
  #
34
- def initialize(message_id, message_or_options = nil)
35
- @message_id = message_id.to_sym
34
+ def initialize(code, message_or_options = nil)
35
+ @code = code.to_sym
36
36
  case message_or_options
37
37
  when Hash
38
38
  @options = message_or_options
@@ -45,7 +45,7 @@ module Noise
45
45
 
46
46
  # @return [String]
47
47
  def message
48
- @message.presence || I18n.t("noise.#{self.class.name.demodulize.underscore}.#{@message_id}", @options)
48
+ @message.presence || I18n.t("noise.#{self.class.name.demodulize.underscore}.#{@code}", @options)
49
49
  end
50
50
 
51
51
  # @return [String]
@@ -89,7 +89,7 @@ module Noise
89
89
 
90
90
  # 404
91
91
  class NotFoundError < PublicError
92
- def initialize(message_id = 'not_found', message = nil)
92
+ def initialize(code = :not_found, message = nil)
93
93
  super
94
94
  end
95
95
  end
@@ -101,7 +101,7 @@ module Noise
101
101
 
102
102
  # 415
103
103
  class UnsupportedMediaTypeError < PublicError
104
- def initialize(message_id = 'unsupported_media_type', message = nil)
104
+ def initialize(code = :unsupported_media_type, message = nil)
105
105
  super
106
106
  end
107
107
  end
@@ -109,7 +109,7 @@ module Noise
109
109
 
110
110
  # 422
111
111
  class UnprocessableEntityError < PublicError
112
- def initialize(message_id = :unprocessable_entity, message = nil)
112
+ def initialize(code = :unprocessable_entity, message = nil)
113
113
  super
114
114
  end
115
115
  end
@@ -5,9 +5,7 @@ module Noise
5
5
  # Serializes api level errors to general errors format.
6
6
  #
7
7
  class PublicErrorSerializer < ErrorSerializer
8
- def code
9
- object.message_id
10
- end
8
+ delegate :code, to: :object
11
9
 
12
10
  def title
13
11
  object.message
@@ -8,11 +8,11 @@ module Noise
8
8
  class RateLimitError < PublicError
9
9
  attr_reader :retry_after
10
10
 
11
- # @param message_id [Symbol]
11
+ # @param code [Symbol]
12
12
  # @param [String] retry_after
13
13
  #
14
- def initialize(message_id, retry_after:)
15
- super(message_id)
14
+ def initialize(code, retry_after:)
15
+ super(code)
16
16
 
17
17
  @retry_after = retry_after
18
18
  end
data/lib/noise/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  module Noise
4
- VERSION = '1.0.1'
4
+ VERSION = '1.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: white_noise
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tema Bolshakov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-04 00:00:00.000000000 Z
11
+ date: 2018-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
237
  version: '0'
238
238
  requirements: []
239
239
  rubyforge_project:
240
- rubygems_version: 2.6.11
240
+ rubygems_version: 2.7.7
241
241
  signing_key:
242
242
  specification_version: 4
243
243
  summary: Defines middleware which renders exceptions and notifies Bugsnag.