salestation 3.7.0 → 4.0.1
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/responses.rb +19 -4
- 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: ee35e90cf574b4f34cc2105366dbd8a5b9a3fedd8f1c5dd8313b45406055a553
|
4
|
+
data.tar.gz: 91c6dec1705886e385d4c40ddad5c974b62bc315faa4d1e5419e9db2479900a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6c123447543bf3fd0c7e9a6633e6137816d729fd516c7bc1372299203b9827f3d8c1a84f4e90d40af09f79194b1cb8d3fe86cc078a0835f5438b19c8a667a81
|
7
|
+
data.tar.gz: 0a6a27008d3556219cdbcf2109799b80ef71dc34f4b945c0ad159e278a13852a5532915e45c51a2b53705125f0da9635853e52b8c17ac57853d5c0fb4e27b39b
|
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
|
|
@@ -35,9 +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)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class UnprocessableEntityError < Error
|
47
|
+
attribute? :form_errors, Types::Coercible::Hash.optional
|
48
|
+
|
49
|
+
def body
|
50
|
+
super.merge({form_errors: form_errors}.compact)
|
41
51
|
end
|
42
52
|
end
|
43
53
|
|
@@ -48,11 +58,16 @@ module Salestation
|
|
48
58
|
end
|
49
59
|
|
50
60
|
class UnprocessableEntityFromSchemaErrors
|
51
|
-
def self.create(errors:, hints:)
|
61
|
+
def self.create(errors:, hints:, base_error: nil, form_errors: false)
|
52
62
|
message = parse_errors(errors)
|
53
63
|
debug_message = parse_hints(hints)
|
54
64
|
|
55
|
-
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
|
+
)
|
56
71
|
end
|
57
72
|
|
58
73
|
def self.parse_errors(errors)
|
@@ -99,7 +114,7 @@ module Salestation
|
|
99
114
|
Conflict = Error.with_code(409)
|
100
115
|
RequestEntityTooLarge = Error.with_code(413)
|
101
116
|
UnsupportedMediaType = Error.with_code(415)
|
102
|
-
UnprocessableEntity =
|
117
|
+
UnprocessableEntity = UnprocessableEntityError.with_code(422)
|
103
118
|
|
104
119
|
InternalError = Error.with_code(500)
|
105
120
|
ServiceUnavailable = Error.with_code(503)
|
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.1
|
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-12 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: []
|