glia-errors 0.6.1 → 0.7.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 +23 -6
- data/glia-errors.gemspec +1 -1
- data/lib/glia/errors/client_errors.rb +17 -18
- data/lib/glia/errors/error.rb +5 -0
- data/lib/glia/errors/server_errors.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f938565ae0608918f0808c950e1d2621f7d8ef2d347cb9146a37fc1af461a519
|
4
|
+
data.tar.gz: 7d8d9672987fe83c77884532e052adee18e3e980462176b6482dd1a41fb755ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f09300cb765f7ce0fe8d57cce7f8259303acd5dec9ffd61a36307ba0afb9d89c17ca95eb8010526a442ab0028da8fc9c61821f7fbe3cd5727c5d0df2a33e3821
|
7
|
+
data.tar.gz: 8208ee1f6c9e00975df486a1d8fb3f1457f38a576970f15485191f9639340b0ff5247dbcf527f2474ef1f0696ff519994985e9917c91949c33c9e6bcbc9a3c42
|
data/README.md
CHANGED
@@ -18,7 +18,18 @@ require 'glia/errors'
|
|
18
18
|
|
19
19
|
### For Glia developers
|
20
20
|
|
21
|
-
####
|
21
|
+
#### Create Glia error manually
|
22
|
+
|
23
|
+
1. Select error from the [error list](https://internal-docs.at.samo.io/glia-errors/elixir/api-reference.html#modules)
|
24
|
+
- Documentation is for Elixir, however, the errors are the same and their initiation is very similar
|
25
|
+
2. Initialize the error according to the error documentation
|
26
|
+
|
27
|
+
Example:
|
28
|
+
```
|
29
|
+
glia_error = Glia::Errors::ResourceNotFoundError.new(resource: :engagement)
|
30
|
+
```
|
31
|
+
|
32
|
+
#### Create Glia error from `dry-validation` result
|
22
33
|
|
23
34
|
Currently 2 `dry-validation` versions are supported:
|
24
35
|
* `v0` up to `0.13`
|
@@ -29,11 +40,10 @@ schema = Dry::Validation.Schema do
|
|
29
40
|
# ...
|
30
41
|
end
|
31
42
|
result = schema.(input)
|
32
|
-
|
33
|
-
response = error.to_h
|
43
|
+
glia_error = Glia::Errors.from_dry_validation_result(result)
|
34
44
|
```
|
35
45
|
|
36
|
-
####
|
46
|
+
#### Create Glia error from `dry-validation` that contains custom errors
|
37
47
|
|
38
48
|
If you have custom `dry-validation` predicates and error messages you can specify a custom error map.
|
39
49
|
Custom error map takes priority over standard error mapping.
|
@@ -46,8 +56,15 @@ ERROR_MAP = {
|
|
46
56
|
Glia::Errors::InvalidFormatError.new(field: field)
|
47
57
|
end
|
48
58
|
}
|
49
|
-
|
50
|
-
|
59
|
+
glia_error = Glia::Errors.from_dry_validation_result(result, ERROR_MAP)
|
60
|
+
```
|
61
|
+
|
62
|
+
#### Convert Glia error to a hash
|
63
|
+
|
64
|
+
You can use this to convert Glia error to hash, so that later it can be converted to JSON.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
glia_error.to_h
|
51
68
|
```
|
52
69
|
|
53
70
|
### For REST API integrators
|
data/glia-errors.gemspec
CHANGED
@@ -7,8 +7,8 @@ module Glia
|
|
7
7
|
def initialize(error_details:, message: nil)
|
8
8
|
super(
|
9
9
|
type: INPUT_VALIDATION_ERROR,
|
10
|
-
ref:
|
11
|
-
message: message,
|
10
|
+
ref: create_ref(INPUT_VALIDATION_ERROR),
|
11
|
+
message: message || 'Input is invalid',
|
12
12
|
error_details: error_details
|
13
13
|
)
|
14
14
|
end
|
@@ -18,7 +18,7 @@ module Glia
|
|
18
18
|
def initialize(field:, message: nil)
|
19
19
|
super(
|
20
20
|
type: INVALID_NUMBER_ERROR,
|
21
|
-
ref:
|
21
|
+
ref: create_ref(INVALID_NUMBER_ERROR),
|
22
22
|
message: message || "#{humanize(field)} value is invalid"
|
23
23
|
)
|
24
24
|
end
|
@@ -28,7 +28,7 @@ module Glia
|
|
28
28
|
def initialize(field:, message: nil)
|
29
29
|
super(
|
30
30
|
type: INVALID_VALUE_ERROR,
|
31
|
-
ref:
|
31
|
+
ref: create_ref(INVALID_VALUE_ERROR),
|
32
32
|
message: message || "#{humanize(field)} value is invalid"
|
33
33
|
)
|
34
34
|
end
|
@@ -38,7 +38,7 @@ module Glia
|
|
38
38
|
def initialize(field:, message: nil)
|
39
39
|
super(
|
40
40
|
type: INVALID_LENGTH_ERROR,
|
41
|
-
ref:
|
41
|
+
ref: create_ref(INVALID_LENGTH_ERROR),
|
42
42
|
message: message || "#{humanize(field)} length is invalid"
|
43
43
|
)
|
44
44
|
end
|
@@ -57,7 +57,7 @@ module Glia
|
|
57
57
|
format ? "has invalid format, required format is #{format}" : 'has invalid format'
|
58
58
|
super(
|
59
59
|
type: INVALID_FORMAT_ERROR,
|
60
|
-
ref:
|
60
|
+
ref: create_ref(INVALID_FORMAT_ERROR),
|
61
61
|
message: message || "#{humanize(field)} #{default_message}"
|
62
62
|
)
|
63
63
|
end
|
@@ -76,7 +76,7 @@ module Glia
|
|
76
76
|
def initialize(field:, type:, message: nil)
|
77
77
|
super(
|
78
78
|
type: INVALID_TYPE_ERROR,
|
79
|
-
ref:
|
79
|
+
ref: create_ref(INVALID_TYPE_ERROR),
|
80
80
|
message: message || "#{humanize(field)} must be of type #{type}",
|
81
81
|
error_details: { type: type }
|
82
82
|
)
|
@@ -87,7 +87,7 @@ module Glia
|
|
87
87
|
def initialize(field:, message: nil)
|
88
88
|
super(
|
89
89
|
type: MISSING_VALUE_ERROR,
|
90
|
-
ref:
|
90
|
+
ref: create_ref(MISSING_VALUE_ERROR),
|
91
91
|
message: message || "#{humanize(field)} is missing"
|
92
92
|
)
|
93
93
|
end
|
@@ -97,7 +97,7 @@ module Glia
|
|
97
97
|
def initialize(field:, message: nil)
|
98
98
|
super(
|
99
99
|
type: UNKNOWN_ERROR,
|
100
|
-
ref:
|
100
|
+
ref: create_ref(UNKNOWN_ERROR),
|
101
101
|
message: message || "#{humanize(field)} validation failed with unknown error"
|
102
102
|
)
|
103
103
|
end
|
@@ -109,7 +109,7 @@ module Glia
|
|
109
109
|
|
110
110
|
super(
|
111
111
|
type: RESOURCE_NOT_FOUND_ERROR,
|
112
|
-
ref:
|
112
|
+
ref: create_ref(RESOURCE_NOT_FOUND_ERROR),
|
113
113
|
message: message || "#{humanize(resource)} not found",
|
114
114
|
error_details: { resource: resource }
|
115
115
|
)
|
@@ -122,7 +122,7 @@ module Glia
|
|
122
122
|
|
123
123
|
super(
|
124
124
|
type: NOT_VERIFIED_ERROR,
|
125
|
-
ref:
|
125
|
+
ref: create_ref(NOT_VERIFIED_ERROR),
|
126
126
|
message: message || "#{humanize(resource)} is not verified",
|
127
127
|
error_details: { resource: resource }
|
128
128
|
)
|
@@ -140,7 +140,7 @@ module Glia
|
|
140
140
|
}(s)"
|
141
141
|
super(
|
142
142
|
type: REMAINING_ASSOCIATION_ERROR,
|
143
|
-
ref:
|
143
|
+
ref: create_ref(REMAINING_ASSOCIATION_ERROR),
|
144
144
|
message: message || "#{humanize(resource)} #{default_message}",
|
145
145
|
error_details: { resource: resource, associated_resource: associated_resource }
|
146
146
|
)
|
@@ -153,7 +153,7 @@ module Glia
|
|
153
153
|
|
154
154
|
super(
|
155
155
|
type: LIMIT_EXCEEDED_ERROR,
|
156
|
-
ref:
|
156
|
+
ref: create_ref(LIMIT_EXCEEDED_ERROR),
|
157
157
|
message: message || "#{humanize(resource)} count must not exceed #{max}",
|
158
158
|
error_details: { resource: resource, max: max }
|
159
159
|
)
|
@@ -166,7 +166,7 @@ module Glia
|
|
166
166
|
|
167
167
|
super(
|
168
168
|
type: RESOURCE_ALREADY_EXISTS_ERROR,
|
169
|
-
ref:
|
169
|
+
ref: create_ref(RESOURCE_ALREADY_EXISTS_ERROR),
|
170
170
|
message: message || "#{humanize(resource)} already exists",
|
171
171
|
error_details: { resource: resource }
|
172
172
|
)
|
@@ -180,7 +180,7 @@ module Glia
|
|
180
180
|
|
181
181
|
super(
|
182
182
|
type: INVALID_RESOURCE_STATE_ERROR,
|
183
|
-
ref:
|
183
|
+
ref: create_ref(INVALID_RESOURCE_STATE_ERROR),
|
184
184
|
message: message || "#{humanize(resource)} is in invalid state: #{state}",
|
185
185
|
error_details: { resource: resource, state: state }
|
186
186
|
)
|
@@ -191,7 +191,7 @@ module Glia
|
|
191
191
|
def initialize(message: nil)
|
192
192
|
super(
|
193
193
|
type: AUTHORIZATION_ERROR,
|
194
|
-
ref:
|
194
|
+
ref: create_ref(AUTHORIZATION_ERROR),
|
195
195
|
message: message || 'You do not have permissions to perform the action'
|
196
196
|
)
|
197
197
|
end
|
@@ -201,8 +201,7 @@ module Glia
|
|
201
201
|
def initialize(message: nil)
|
202
202
|
super(
|
203
203
|
type: RECIPIENT_OPTED_OUT_ERROR,
|
204
|
-
ref:
|
205
|
-
'https://docs.glia.com/glia-dev/reference/webhooks#example-engagementrequestfailure-event-with-fail_error',
|
204
|
+
ref: create_ref(RECIPIENT_OPTED_OUT_ERROR),
|
206
205
|
message: message || 'Recipient has opted out'
|
207
206
|
)
|
208
207
|
end
|
data/lib/glia/errors/error.rb
CHANGED
@@ -7,7 +7,7 @@ module Glia
|
|
7
7
|
def initialize(message: nil)
|
8
8
|
super(
|
9
9
|
type: INTERNAL_SERVER_ERROR,
|
10
|
-
ref:
|
10
|
+
ref: create_ref(INTERNAL_SERVER_ERROR),
|
11
11
|
message: message || 'Internal server error'
|
12
12
|
)
|
13
13
|
end
|
@@ -17,7 +17,7 @@ module Glia
|
|
17
17
|
def initialize(message: nil)
|
18
18
|
super(
|
19
19
|
type: SERVICE_UNAVAILABLE_ERROR,
|
20
|
-
ref:
|
20
|
+
ref: create_ref(SERVICE_UNAVAILABLE_ERROR),
|
21
21
|
message: message || 'Service unavailable'
|
22
22
|
)
|
23
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glia-errors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glia TechMovers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ''
|
14
14
|
email:
|