glia-errors 0.9.0 → 0.10.1

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: f6960566975ff5446a08dfc290bf2b1ebe1d3543df49e79ffb2ec24ad8f87763
4
- data.tar.gz: 06f24196271555ebc4f5e2ac217399c8ad161fb0f6717cbe990fd8b7cc607da7
3
+ metadata.gz: 110bf7c1b2d1b5855f92c842563f59fe6b93157b5bee67af2e446b212dc2b108
4
+ data.tar.gz: e99a9338aa7995f17865a25ac6dc4c60fbfc0aa883d507add47043b0ec9f448a
5
5
  SHA512:
6
- metadata.gz: bf8a1d4cc12a450424668ddf201f7cdf20293e8cca5c4269f6a405bbd91718b40e2e6011537cd39643728510fd75b0e51e05f84dcebf85ea5bcadb3a637f6ce2
7
- data.tar.gz: 9ae41cf5a5f711c9a795ca7aeb6e67bc31c57c2926e05bd898b3645c4e4be6acfd1e94eafbbc687a6c0bb8bda512e0cbaa77a6c01f4c6a1b360149f8effcb231
6
+ metadata.gz: 74b6285d294a404baa2d59e3406d1f021c2319aab4bb73f7f4cda571dce46eb55250347bfd8c66dddab43404357c5e6a6c996a1bc936857498f3b148e50c185a
7
+ data.tar.gz: 96ef53cbee527e3e64606223c81a0335954a40187bd830231fc0d07160ce82554894c2be1d38e51cc2f271c661affd301b0640ac4b3339045574c4c944d02170
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.9.0'
8
+ spec.version = '0.10.1'
9
9
  spec.authors = ['Glia TechMovers']
10
10
  spec.email = ['techmovers@glia.com']
11
11
 
@@ -5,6 +5,12 @@ module Glia
5
5
  # rubocop:disable Style/Documentation
6
6
  class InputValidationError < Error
7
7
  def initialize(error_details:, message: nil)
8
+ raise ArgumentError, 'At least 1 error detail is required' if error_details.keys.count.zero?
9
+
10
+ error_details.each_value do |value|
11
+ raise ArgumentError, 'error_details values must be lists' unless value.is_a?(Array)
12
+ end
13
+
8
14
  super(
9
15
  type: INPUT_VALIDATION_ERROR,
10
16
  ref: create_ref(INPUT_VALIDATION_ERROR),
@@ -131,7 +137,7 @@ module Glia
131
137
 
132
138
  class ResourceNotFoundError < Error
133
139
  def initialize(resource:, message: nil)
134
- assert_snake_case(resource)
140
+ Naming.assert_snake_case(resource)
135
141
 
136
142
  super(
137
143
  type: RESOURCE_NOT_FOUND_ERROR,
@@ -144,7 +150,7 @@ module Glia
144
150
 
145
151
  class NotVerifiedError < Error
146
152
  def initialize(resource:, message: nil)
147
- assert_snake_case(resource)
153
+ Naming.assert_snake_case(resource)
148
154
 
149
155
  super(
150
156
  type: NOT_VERIFIED_ERROR,
@@ -157,8 +163,8 @@ module Glia
157
163
 
158
164
  class RemainingAssociationError < Error
159
165
  def initialize(resource:, associated_resource:, message: nil)
160
- assert_snake_case(resource)
161
- assert_snake_case(associated_resource)
166
+ Naming.assert_snake_case(resource)
167
+ Naming.assert_snake_case(associated_resource)
162
168
 
163
169
  default_message =
164
170
  "cannot be modified/deleted because it is associated to one or more #{
@@ -175,7 +181,7 @@ module Glia
175
181
 
176
182
  class ResourceLimitExceededError < Error
177
183
  def initialize(resource:, max:, message: nil)
178
- assert_snake_case(resource)
184
+ Naming.assert_snake_case(resource)
179
185
 
180
186
  super(
181
187
  type: LIMIT_EXCEEDED_ERROR,
@@ -188,7 +194,7 @@ module Glia
188
194
 
189
195
  class ResourceAlreadyExistsError < Error
190
196
  def initialize(resource:, message: nil)
191
- assert_snake_case(resource)
197
+ Naming.assert_snake_case(resource)
192
198
 
193
199
  super(
194
200
  type: RESOURCE_ALREADY_EXISTS_ERROR,
@@ -201,8 +207,8 @@ module Glia
201
207
 
202
208
  class InvalidResourceStateError < Error
203
209
  def initialize(resource:, state:, message: nil)
204
- assert_snake_case(resource)
205
- assert_snake_case(state)
210
+ Naming.assert_snake_case(resource)
211
+ Naming.assert_snake_case(state)
206
212
 
207
213
  super(
208
214
  type: INVALID_RESOURCE_STATE_ERROR,
@@ -322,6 +328,25 @@ module Glia
322
328
  )
323
329
  end
324
330
  end
331
+
332
+ class HeadersValidationError < Error
333
+ def initialize(error_details:, message: nil)
334
+ raise ArgumentError, 'At least 1 error detail is required' if error_details.keys.count.zero?
335
+
336
+ error_details.each_value do |value|
337
+ raise ArgumentError, 'error_details values must be lists' unless value.is_a?(Array)
338
+ end
339
+
340
+ error_details.each_key { |key| Naming.assert_header(key) }
341
+
342
+ super(
343
+ type: HEADERS_VALIDATION_ERROR,
344
+ ref: create_ref(HEADERS_VALIDATION_ERROR),
345
+ message: message || 'Headers are invalid',
346
+ error_details: error_details
347
+ )
348
+ end
349
+ end
325
350
  # rubocop:enable Style/Documentation
326
351
  end
327
352
  end
@@ -6,7 +6,6 @@ module Glia
6
6
  module Errors
7
7
  # Base error
8
8
  class Error
9
- SNAKE_CASE_REGEX = /^[a-z0-9]+(_[a-z0-9]+)*$/.freeze
10
9
  attr_reader :type, :ref, :message, :error_details
11
10
 
12
11
  def initialize(type:, ref:, message: nil, error_details: nil)
@@ -45,12 +44,6 @@ module Glia
45
44
  [TrueClass, FalseClass, String, Integer, Float, Symbol].include?(details.class)
46
45
  end
47
46
 
48
- def assert_snake_case(value)
49
- return if value.to_s.match(SNAKE_CASE_REGEX)
50
-
51
- raise ArgumentError, "Expected '#{value}' to be in snake case"
52
- end
53
-
54
47
  def create_ref(type)
55
48
  fragment = type.gsub('_', '-')
56
49
  "https://docs.glia.com/glia-dev/reference/errors##{fragment}"
@@ -28,6 +28,7 @@ module Glia
28
28
  TELEPHONY_PROVIDER_QUEUE_LIMIT_EXCEEDED_ERROR = 'telephony_provider_queue_limit_exceeded_error'
29
29
  TWILIO_MESSAGING_SERVICE_CONFIGURATION_ERROR = 'twilio_messaging_service_configuration_error'
30
30
  UNREACHABLE_DESTINATION_ERROR = 'unreachable_destination_error'
31
+ HEADERS_VALIDATION_ERROR = 'headers_validation_error'
31
32
 
32
33
  # Server errors
33
34
  INTERNAL_SERVER_ERROR = 'internal_server_error'
@@ -29,6 +29,22 @@ module Glia
29
29
  private_class_method def self.upcase_first(value)
30
30
  value[0].upcase.concat(value[1..-1])
31
31
  end
32
+
33
+ SNAKE_CASE_REGEX = /\A[a-z0-9]+(_[a-z0-9]+)*\z/.freeze
34
+
35
+ def self.assert_snake_case(value)
36
+ return if value.to_s.match(SNAKE_CASE_REGEX)
37
+
38
+ raise ArgumentError, "Expected '#{value}' to be in snake case"
39
+ end
40
+
41
+ HEADER_REGEX = /\A[A-Z0-9]+[a-z0-9]*(-[A-Z0-9]+[a-zz0-9]*)*\z/.freeze
42
+
43
+ def self.assert_header(value)
44
+ return if value.to_s.match(HEADER_REGEX)
45
+
46
+ raise ArgumentError, "Expected '#{value}' to be a valid header"
47
+ end
32
48
  end
33
49
  end
34
50
  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.9.0
4
+ version: 0.10.1
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-17 00:00:00.000000000 Z
11
+ date: 2021-03-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ''
14
14
  email: