error_normalizer 0.2.3 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -3
- data/.rubocop.yml +1 -2
- data/.ruby-version +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +8 -11
- data/error_normalizer.gemspec +3 -2
- data/lib/error_normalizer/schema_path_translator.rb +5 -1
- data/lib/error_normalizer/version.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb14b964d184febd948c8965030548fdaf37d7ac39d8fac6e4fabebdf518150b
|
4
|
+
data.tar.gz: 87220e4f46faae5c1f2cf1ed8813978d60720910ccb3662e45698ae826b2b435
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2765ca075126a57926c60da14b84add0dd0a6dad55861640f034de164353f38dc1b9c5d4de6588d5ae8ff267f69a0f700354771e4b41b3af8a92d6c50c52b40f
|
7
|
+
data.tar.gz: 4cfa14ae30cdf1ecf5c3963716ba908269865ba8c3c539b23ea70b83b999a1a1b1fcff43c2048396a31b46c0de2a64efdb482e4fa2aab5c0f70bd6b5c5e47e69
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
[![Build Status](https://jenkins.yalantis.com/buildStatus/icon?job=error_normalizer)](https://jenkins.yalantis.com/job/error_normalizer/)
|
2
|
+
|
1
3
|
# Hola :call_me_hand:
|
2
4
|
|
3
|
-
This gem was born out of need to have
|
5
|
+
This gem was born out of the need to have an established universal error format to be consumed by frontend (JS), Android and iOS clients.
|
4
6
|
|
5
7
|
## API error format
|
6
8
|
|
@@ -20,9 +22,10 @@ In our projects we have a convention, that in case of a failed request (422) bac
|
|
20
22
|
Each error object **must have** 4 required fields: `key`, `type`, `message` and `payload`.
|
21
23
|
|
22
24
|
- `key` is a concise error code that will be used in a user-friendly translations
|
23
|
-
- `type` may be `params`, `custom` or something else
|
25
|
+
- `type` may be `params`, `custom`, `rule` or something else
|
24
26
|
- `params` means that some parameter that the backend received was wrong
|
25
|
-
- `
|
27
|
+
- `rule` covers cases of the high-level (business) rules which validate against several fields simultaneously
|
28
|
+
- `custom` covers everything else
|
26
29
|
- `message` is a "default" or "fallback" error message in plain English that may be used if client does not have translation for the error code
|
27
30
|
- `payload` contains other useful data that assists client error handling. For example, in case of `type: "params"` we can provide a _path_ to the invalid paramter.
|
28
31
|
|
@@ -76,7 +79,7 @@ For more information about supported errors and how they would be parsed please
|
|
76
79
|
|
77
80
|
**TL;DR:** Add `_rule` to the [custom validation block](https://dry-rb.org/gems/dry-validation/custom-validation-blocks/) names (adding this to the [high-level rules](https://dry-rb.org/gems/dry-validation/high-level-rules/) won't harm either, praise the consistency!).
|
78
81
|
|
79
|
-
**Long version**: When you're using [custom validation blocks](https://dry-rb.org/gems/dry-validation/custom-validation-blocks/) the error output is slightly diffenet. Instead of attribute name it will have a rule name as a key. For example, GIVEN this schema
|
82
|
+
**Long version**: When you're using [custom validation blocks](https://dry-rb.org/gems/dry-validation/custom-validation-blocks/) the error output is slightly diffenet. Instead of the attribute name it will have a rule name as a key. For example, GIVEN this schema
|
80
83
|
|
81
84
|
schema = Dry::Validation.Schema do
|
82
85
|
configure do
|
@@ -144,7 +147,7 @@ You can customize rule name match pattern, type name or turn off this feature co
|
|
144
147
|
|
145
148
|
##### Full message translation
|
146
149
|
|
147
|
-
This feature
|
150
|
+
This feature allows to define the localization for schema attributes (think of `path` that you get in `payload`), translate it with I18n and concatenate it with the error messages.
|
148
151
|
|
149
152
|
schema = Dry::Validation.Schema do
|
150
153
|
required(:user).schema do
|
@@ -242,12 +245,6 @@ THEN we can normalize object errors to API error format
|
|
242
245
|
# :type=>"params"
|
243
246
|
# }]
|
244
247
|
|
245
|
-
## TODO
|
246
|
-
|
247
|
-
- configure Gitlab CI
|
248
|
-
- parse ActiveModel error mesasges
|
249
|
-
- support array of errors as an input
|
250
|
-
|
251
248
|
## License
|
252
249
|
|
253
250
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/error_normalizer.gemspec
CHANGED
@@ -5,11 +5,11 @@ require_relative 'lib/error_normalizer/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'error_normalizer'
|
7
7
|
spec.version = ErrorNormalizer::VERSION
|
8
|
-
spec.authors = ['Denis Kondratenko']
|
8
|
+
spec.authors = ['Denis Kondratenko', 'Aleksandra Stolyar']
|
9
9
|
spec.email = ['di.kondratenko@gmail.com']
|
10
10
|
|
11
11
|
spec.summary = 'Normalize dry-validation and ActiveModel errors to the universal format'
|
12
|
-
spec.homepage = 'https://
|
12
|
+
spec.homepage = 'https://github.com/Yalantis/error_normalizer'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
15
15
|
# Specify which files should be added to the gem when it is released.
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
19
|
end
|
20
20
|
spec.require_paths = ['lib']
|
21
|
+
spec.required_ruby_version = '~> 2.0'
|
21
22
|
|
22
23
|
spec.add_runtime_dependency 'dry-configurable', '~> 0.7.0'
|
23
24
|
spec.add_development_dependency 'i18n', '~> 1'
|
@@ -42,7 +42,7 @@ class ErrorNormalizer
|
|
42
42
|
translated_tokens << translate_token(token, i, tokens)
|
43
43
|
end
|
44
44
|
|
45
|
-
translated_tokens.join(' ')
|
45
|
+
upcase_sentence(translated_tokens.join(' '))
|
46
46
|
end
|
47
47
|
|
48
48
|
private
|
@@ -69,5 +69,9 @@ class ErrorNormalizer
|
|
69
69
|
lookup << token
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
73
|
+
def upcase_sentence(string)
|
74
|
+
string.length > 0 ? string[0].upcase.concat(string[1..-1]) : ""
|
75
|
+
end
|
72
76
|
end
|
73
77
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: error_normalizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Kondratenko
|
8
|
+
- Aleksandra Stolyar
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2019-
|
12
|
+
date: 2019-06-05 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: dry-configurable
|
@@ -132,6 +133,7 @@ files:
|
|
132
133
|
- ".gitignore"
|
133
134
|
- ".rspec"
|
134
135
|
- ".rubocop.yml"
|
136
|
+
- ".ruby-version"
|
135
137
|
- Gemfile
|
136
138
|
- Gemfile.lock
|
137
139
|
- LICENSE.txt
|
@@ -145,7 +147,7 @@ files:
|
|
145
147
|
- lib/error_normalizer/normalizer.rb
|
146
148
|
- lib/error_normalizer/schema_path_translator.rb
|
147
149
|
- lib/error_normalizer/version.rb
|
148
|
-
homepage: https://
|
150
|
+
homepage: https://github.com/Yalantis/error_normalizer
|
149
151
|
licenses:
|
150
152
|
- MIT
|
151
153
|
metadata: {}
|
@@ -155,9 +157,9 @@ require_paths:
|
|
155
157
|
- lib
|
156
158
|
required_ruby_version: !ruby/object:Gem::Requirement
|
157
159
|
requirements:
|
158
|
-
- - "
|
160
|
+
- - "~>"
|
159
161
|
- !ruby/object:Gem::Version
|
160
|
-
version: '0'
|
162
|
+
version: '2.0'
|
161
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
164
|
requirements:
|
163
165
|
- - ">="
|