salestation 3.8.0 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -0
- data/lib/salestation/app/errors.rb +17 -8
- data/lib/salestation/web/error_mapper.rb +8 -7
- data/lib/salestation/web/extractors.rb +4 -2
- data/lib/salestation/web/responses.rb +12 -5
- data/salestation.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85ac2feb504421f1ab20912abbf6994765d3ad6b743360a4e47c67a5bb362774
|
4
|
+
data.tar.gz: 3e6571aeb33d1c2edd94857a6de854e477f8e3a87a2abeac8d352634e01e3012
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d0a4278a94c18bc1a5a5286c0b3941701fda3182d9bcbc27d5b29ccf57841b296b618a75ef67fe1e8a3e88f8c5a649fc3100803d2e79c1d812b0f90b2c13e12
|
7
|
+
data.tar.gz: 80a64adaf82c53f673926a47cc389ae8554c589aa52e41c84ee23a68807d1c49b098c72bf5a338cd0255f689176c0e44f15b7fe0389ea3a90ec89d0bd3a54827
|
data/README.md
CHANGED
@@ -75,6 +75,28 @@ Salestation allows and recommends you to define your own custom errors. This is
|
|
75
75
|
})
|
76
76
|
```
|
77
77
|
|
78
|
+
### Providing custom error fields
|
79
|
+
|
80
|
+
If you need to specify additional error fields you can use `from` method.
|
81
|
+
`from` accepts base error on which the rest of the response is built.
|
82
|
+
Base error must be a hash or implement `to_h` method.
|
83
|
+
|
84
|
+
Example:
|
85
|
+
|
86
|
+
```
|
87
|
+
App::Errors::Conflict.from({details: 'details'}, message: 'message', debug_message: 'debug_message')
|
88
|
+
```
|
89
|
+
|
90
|
+
Response:
|
91
|
+
|
92
|
+
```javascript
|
93
|
+
{
|
94
|
+
"details": "details",
|
95
|
+
"message": "message",
|
96
|
+
"debug_message": "debug_message"
|
97
|
+
}
|
98
|
+
```
|
99
|
+
|
78
100
|
### Using Extractors
|
79
101
|
|
80
102
|
Salestation provides extractors to fetch parameters from the request and pass them to the chain.
|
@@ -3,43 +3,52 @@
|
|
3
3
|
module Salestation
|
4
4
|
class App
|
5
5
|
module Errors
|
6
|
-
class
|
6
|
+
class Error < Dry::Struct
|
7
|
+
attribute? :base_error, Types::Coercible::Hash
|
8
|
+
|
9
|
+
def self.from(base_error, overrides = {})
|
10
|
+
new(**overrides, base_error: base_error.to_h)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class InvalidInput < Error
|
7
15
|
attribute :errors, Types::Strict::Hash
|
8
16
|
attribute :hints, Types::Coercible::Hash.default({}.freeze)
|
9
17
|
attribute? :debug_message, Types::Strict::String
|
18
|
+
attribute? :form_errors, Types::Strict::Bool.default(false)
|
10
19
|
end
|
11
20
|
|
12
|
-
class DependencyCurrentlyUnavailable <
|
21
|
+
class DependencyCurrentlyUnavailable < Error
|
13
22
|
attribute :message, Types::Strict::String
|
14
23
|
attribute? :debug_message, Types::Strict::String
|
15
24
|
end
|
16
25
|
|
17
|
-
class RequestedResourceNotFound <
|
26
|
+
class RequestedResourceNotFound < Error
|
18
27
|
attribute :message, Types::Strict::String
|
19
28
|
attribute? :debug_message, Types::Strict::String
|
20
29
|
end
|
21
30
|
|
22
|
-
class Forbidden <
|
31
|
+
class Forbidden < Error
|
23
32
|
attribute :message, Types::Strict::String
|
24
33
|
attribute? :debug_message, Types::Strict::String
|
25
34
|
end
|
26
35
|
|
27
|
-
class Conflict <
|
36
|
+
class Conflict < Error
|
28
37
|
attribute :message, Types::Strict::String
|
29
38
|
attribute :debug_message, Types::Strict::String
|
30
39
|
end
|
31
40
|
|
32
|
-
class NotAcceptable <
|
41
|
+
class NotAcceptable < Error
|
33
42
|
attribute :message, Types::Strict::String
|
34
43
|
attribute :debug_message, Types::Strict::String
|
35
44
|
end
|
36
45
|
|
37
|
-
class UnsupportedMediaType <
|
46
|
+
class UnsupportedMediaType < Error
|
38
47
|
attribute :message, Types::Strict::String
|
39
48
|
attribute :debug_message, Types::Strict::String
|
40
49
|
end
|
41
50
|
|
42
|
-
class RequestEntityTooLarge <
|
51
|
+
class RequestEntityTooLarge < Error
|
43
52
|
attribute :message, Types::Strict::String
|
44
53
|
attribute? :debug_message, Types::Strict::String
|
45
54
|
end
|
@@ -12,26 +12,27 @@ module Salestation
|
|
12
12
|
App::Errors::DependencyCurrentlyUnavailable => -> (error) {
|
13
13
|
Responses::ServiceUnavailable.new(
|
14
14
|
message: error.message,
|
15
|
-
debug_message: "Please try again later"
|
15
|
+
debug_message: "Please try again later",
|
16
|
+
base_error: error.base_error
|
16
17
|
)
|
17
18
|
},
|
18
19
|
App::Errors::RequestedResourceNotFound => -> (error) {
|
19
|
-
Responses::NotFound.new(message: error.message, debug_message: error.debug_message)
|
20
|
+
Responses::NotFound.new(message: error.message, debug_message: error.debug_message, base_error: error.base_error)
|
20
21
|
},
|
21
22
|
App::Errors::Forbidden => -> (error) {
|
22
|
-
Responses::Forbidden.new(message: error.message, debug_message: error.debug_message)
|
23
|
+
Responses::Forbidden.new(message: error.message, debug_message: error.debug_message, base_error: error.base_error)
|
23
24
|
},
|
24
25
|
App::Errors::Conflict => -> (error) {
|
25
|
-
Responses::Conflict.new(message: error.message, debug_message: error.debug_message)
|
26
|
+
Responses::Conflict.new(message: error.message, debug_message: error.debug_message, base_error: error.base_error)
|
26
27
|
},
|
27
28
|
App::Errors::NotAcceptable => -> (error) {
|
28
|
-
Responses::NotAcceptable.new(message: error.message, debug_message: error.debug_message)
|
29
|
+
Responses::NotAcceptable.new(message: error.message, debug_message: error.debug_message, base_error: error.base_error)
|
29
30
|
},
|
30
31
|
App::Errors::UnsupportedMediaType => -> (error) {
|
31
|
-
Responses::UnsupportedMediaType.new(message: error.message, debug_message: error.debug_message)
|
32
|
+
Responses::UnsupportedMediaType.new(message: error.message, debug_message: error.debug_message, base_error: error.base_error)
|
32
33
|
},
|
33
34
|
App::Errors::RequestEntityTooLarge => -> (error) {
|
34
|
-
Responses::RequestEntityTooLarge.new(message: error.message, debug_message: error.debug_message)
|
35
|
+
Responses::RequestEntityTooLarge.new(message: error.message, debug_message: error.debug_message, base_error: error.base_error)
|
35
36
|
}
|
36
37
|
}.freeze
|
37
38
|
|
@@ -125,8 +125,10 @@ module Salestation
|
|
125
125
|
extracted_data[filter] = request_hash[stringified_key] if request_hash.key?(stringified_key)
|
126
126
|
when Hash
|
127
127
|
filter.each do |key, nested_filters|
|
128
|
-
|
129
|
-
|
128
|
+
stringified_key = key.to_s
|
129
|
+
if request_hash.key?(stringified_key)
|
130
|
+
value = request_hash.fetch(stringified_key)
|
131
|
+
extracted_data[key] = value.nil? ? nil : extract(nested_filters, value)
|
130
132
|
end
|
131
133
|
end
|
132
134
|
end
|
@@ -35,17 +35,19 @@ module Salestation
|
|
35
35
|
attribute :debug_message, Types::Coercible::String.default('')
|
36
36
|
attribute :context, Types::Hash.default({}.freeze)
|
37
37
|
attribute :headers, Types::Hash.default({}.freeze)
|
38
|
+
attribute? :base_error, Types::Coercible::Hash
|
38
39
|
|
39
40
|
def body
|
40
|
-
|
41
|
+
# Merge into `base_error` to ensure standard fields are not overriden
|
42
|
+
(base_error || {}).merge(message: message, debug_message: debug_message)
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
46
|
class UnprocessableEntityError < Error
|
45
|
-
attribute :form_errors, Types::Hash.
|
47
|
+
attribute? :form_errors, Types::Coercible::Hash.optional
|
46
48
|
|
47
49
|
def body
|
48
|
-
super.merge(form_errors:
|
50
|
+
super.merge({form_errors: form_errors}.compact)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -56,11 +58,16 @@ module Salestation
|
|
56
58
|
end
|
57
59
|
|
58
60
|
class UnprocessableEntityFromSchemaErrors
|
59
|
-
def self.create(errors:, hints:)
|
61
|
+
def self.create(errors:, hints:, base_error: nil, form_errors: false)
|
60
62
|
message = parse_errors(errors)
|
61
63
|
debug_message = parse_hints(hints)
|
62
64
|
|
63
|
-
UnprocessableEntity.new(
|
65
|
+
UnprocessableEntity.new(
|
66
|
+
message: message,
|
67
|
+
debug_message: debug_message,
|
68
|
+
form_errors: form_errors ? errors : nil,
|
69
|
+
base_error: base_error
|
70
|
+
)
|
64
71
|
end
|
65
72
|
|
66
73
|
def self.parse_errors(errors)
|
data/salestation.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salestation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glia TechMovers
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -143,7 +143,7 @@ homepage: ''
|
|
143
143
|
licenses:
|
144
144
|
- MIT
|
145
145
|
metadata: {}
|
146
|
-
post_install_message:
|
146
|
+
post_install_message:
|
147
147
|
rdoc_options: []
|
148
148
|
require_paths:
|
149
149
|
- lib
|
@@ -158,8 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
|
-
rubygems_version: 3.0.
|
162
|
-
signing_key:
|
161
|
+
rubygems_version: 3.0.6
|
162
|
+
signing_key:
|
163
163
|
specification_version: 4
|
164
164
|
summary: ''
|
165
165
|
test_files: []
|