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 +5 -5
- data/Gemfile.lock +1 -1
- data/lib/noise/exception_renderer.rb +6 -3
- data/lib/noise/public_error.rb +13 -13
- data/lib/noise/public_error_serializer.rb +1 -3
- data/lib/noise/rate_limit_error.rb +3 -3
- data/lib/noise/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 21fb66b0a6a90391211e78936e2728b55f7f6b1d20fc7fc8a8e3ebe1e2deda9e
|
4
|
+
data.tar.gz: c425d74ed580041961efd908205a5cce5f3022e4d6cf514daba486085c47a1fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f32097f81b7480bac71a0d558fe3e82635487a5a9c9c72faf433612f0b0d492d6e389cd84b3c27597b1ceba505993fb25fac0ffb659f2b6c46601bc920950982
|
7
|
+
data.tar.gz: 1fe0facb00afc93581cf134d6f1ff9a7aa183d5f069ea45ba230b77fafb8a228866ef80b90315b306f299c71e9f0983c7150b57ef5e4d3989053caf3a3c91320
|
data/Gemfile.lock
CHANGED
@@ -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.
|
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
|
-
|
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
|
data/lib/noise/public_error.rb
CHANGED
@@ -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 :
|
13
|
+
attr_reader :code
|
14
14
|
attr_reader :options
|
15
15
|
|
16
|
-
# @overload new(
|
17
|
-
# Instantiate error with given
|
18
|
-
# @param
|
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(
|
21
|
-
# Instantiate error with given
|
20
|
+
# @overload new(code, options)
|
21
|
+
# Instantiate error with given code and options.
|
22
22
|
# Options would be passed to I18n key
|
23
|
-
# @param
|
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(
|
35
|
-
@
|
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}.#{@
|
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(
|
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(
|
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(
|
112
|
+
def initialize(code = :unprocessable_entity, message = nil)
|
113
113
|
super
|
114
114
|
end
|
115
115
|
end
|
@@ -8,11 +8,11 @@ module Noise
|
|
8
8
|
class RateLimitError < PublicError
|
9
9
|
attr_reader :retry_after
|
10
10
|
|
11
|
-
# @param
|
11
|
+
# @param code [Symbol]
|
12
12
|
# @param [String] retry_after
|
13
13
|
#
|
14
|
-
def initialize(
|
15
|
-
super(
|
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
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
|
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-
|
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.
|
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.
|