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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9f3f981c61ebf8676c66ee15e0b326d052978374f8099574d8f84370247e834
4
- data.tar.gz: a4d50d5aabad297607ef9a8c3f2fef743ba1620212cde790e95547ee9559216d
3
+ metadata.gz: f938565ae0608918f0808c950e1d2621f7d8ef2d347cb9146a37fc1af461a519
4
+ data.tar.gz: 7d8d9672987fe83c77884532e052adee18e3e980462176b6482dd1a41fb755ec
5
5
  SHA512:
6
- metadata.gz: fcf46277d4d7f2368999acab163f89e192d76ca0db527e94c39fdbcefe6b4bdf83dd2e6a116eef2eb2568e0a4d005f86dc06729925aa50b1dc9e050564d62093
7
- data.tar.gz: '04281d7946a62f546d3a2e4474336289a83142a2283a622a3abe13988f3d29bf24b66ff1e9aba02a5ce1043cd5232fc262138d1ee061a283e6d4b31a1f13ad98'
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
- #### Map from `dry-validation` result
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
- error = Glia::Errors.from_dry_validation_result(result)
33
- response = error.to_h
43
+ glia_error = Glia::Errors.from_dry_validation_result(result)
34
44
  ```
35
45
 
36
- #### Specifying mapping for custom error message
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
- error = Glia::Errors.from_dry_validation_result(result, ERROR_MAP)
50
- response = error.to_h
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
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'glia-errors'
8
- spec.version = '0.6.1'
8
+ spec.version = '0.7.0'
9
9
  spec.authors = ['Glia TechMovers']
10
10
  spec.email = ['techmovers@glia.com']
11
11
 
@@ -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: "https://example.com/errors/#{INPUT_VALIDATION_ERROR}.html",
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: "https://example.com/errors/#{INVALID_NUMBER_ERROR}.html",
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: "https://example.com/errors/#{INVALID_VALUE_ERROR}.html",
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: "https://example.com/errors/#{INVALID_LENGTH_ERROR}.html",
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: "https://example.com/errors/#{INVALID_FORMAT_ERROR}.html",
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: "https://example.com/errors/#{INVALID_TYPE_ERROR}.html",
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: "https://example.com/errors/#{MISSING_VALUE_ERROR}.html",
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: "https://example.com/errors/#{UNKNOWN_ERROR}.html",
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: "https://example.com/errors/#{RESOURCE_NOT_FOUND_ERROR}.html",
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: "https://example.com/errors/#{NOT_VERIFIED_ERROR}.html",
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: "https://example.com/errors/#{REMAINING_ASSOCIATION_ERROR}.html",
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: "https://example.com/errors/#{LIMIT_EXCEEDED_ERROR}.html",
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: "https://example.com/errors/#{RESOURCE_ALREADY_EXISTS_ERROR}.html",
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: "https://example.com/errors/#{INVALID_RESOURCE_STATE_ERROR}.html",
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: "https://example.com/errors/#{AUTHORIZATION_ERROR}.html",
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
@@ -54,6 +54,11 @@ module Glia
54
54
 
55
55
  raise ArgumentError, "Expected '#{value}' to be in snake case"
56
56
  end
57
+
58
+ def create_ref(type)
59
+ fragment = type.gsub('_', '-')
60
+ "https://docs.glia.com/glia-dev/reference/errors##{fragment}"
61
+ end
57
62
  end
58
63
  end
59
64
  end
@@ -7,7 +7,7 @@ module Glia
7
7
  def initialize(message: nil)
8
8
  super(
9
9
  type: INTERNAL_SERVER_ERROR,
10
- ref: "https://example.com/errors/#{INTERNAL_SERVER_ERROR}.html",
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: "https://example.com/errors/#{SERVICE_UNAVAILABLE_ERROR}.html",
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.6.1
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-04 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ''
14
14
  email: