salestation 3.8.1 → 3.9.0
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 +16 -8
- data/lib/salestation/web/error_mapper.rb +8 -7
- data/lib/salestation/web/responses.rb +5 -3
- 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: c185cbbf51aa9e484fad4fc0099a9b518d11954f5c5c2f11d03f9d086fdeee08
|
4
|
+
data.tar.gz: a8c356c5559e1ee1f02da859513badc848003d35cea3167ae66488c631309fca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c028e25b401034206c66be282335e78e903edac248adaabecd0041bd5a187397f7bda59d894ed35ded3132aed762e3c8596d4aeeee92f6c5b93fbb9549245ec6
|
7
|
+
data.tar.gz: 4dc319fd28ae97aff269c0a6594a2cb271721da31c2ae48d7afd8927ccc352df1526fcfc486146ef55571788bca954de5649ce36a53b73c09767fb28eae99fb1
|
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,51 @@
|
|
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
|
10
18
|
end
|
11
19
|
|
12
|
-
class DependencyCurrentlyUnavailable <
|
20
|
+
class DependencyCurrentlyUnavailable < Error
|
13
21
|
attribute :message, Types::Strict::String
|
14
22
|
attribute? :debug_message, Types::Strict::String
|
15
23
|
end
|
16
24
|
|
17
|
-
class RequestedResourceNotFound <
|
25
|
+
class RequestedResourceNotFound < Error
|
18
26
|
attribute :message, Types::Strict::String
|
19
27
|
attribute? :debug_message, Types::Strict::String
|
20
28
|
end
|
21
29
|
|
22
|
-
class Forbidden <
|
30
|
+
class Forbidden < Error
|
23
31
|
attribute :message, Types::Strict::String
|
24
32
|
attribute? :debug_message, Types::Strict::String
|
25
33
|
end
|
26
34
|
|
27
|
-
class Conflict <
|
35
|
+
class Conflict < Error
|
28
36
|
attribute :message, Types::Strict::String
|
29
37
|
attribute :debug_message, Types::Strict::String
|
30
38
|
end
|
31
39
|
|
32
|
-
class NotAcceptable <
|
40
|
+
class NotAcceptable < Error
|
33
41
|
attribute :message, Types::Strict::String
|
34
42
|
attribute :debug_message, Types::Strict::String
|
35
43
|
end
|
36
44
|
|
37
|
-
class UnsupportedMediaType <
|
45
|
+
class UnsupportedMediaType < Error
|
38
46
|
attribute :message, Types::Strict::String
|
39
47
|
attribute :debug_message, Types::Strict::String
|
40
48
|
end
|
41
49
|
|
42
|
-
class RequestEntityTooLarge <
|
50
|
+
class RequestEntityTooLarge < Error
|
43
51
|
attribute :message, Types::Strict::String
|
44
52
|
attribute? :debug_message, Types::Strict::String
|
45
53
|
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
|
|
@@ -35,9 +35,11 @@ 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
|
|
@@ -56,11 +58,11 @@ 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)
|
60
62
|
message = parse_errors(errors)
|
61
63
|
debug_message = parse_hints(hints)
|
62
64
|
|
63
|
-
UnprocessableEntity.new(message: message, debug_message: debug_message, form_errors: errors)
|
65
|
+
UnprocessableEntity.new(message: message, debug_message: debug_message, form_errors: errors, base_error: base_error)
|
64
66
|
end
|
65
67
|
|
66
68
|
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: 3.
|
4
|
+
version: 3.9.0
|
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-01-14 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: []
|