glia-errors 0.9.0 → 0.11.4

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: bbaef28887dfc236d0f10cb730ac6dc44813f102bc8023da5fda37089815f318
4
+ data.tar.gz: 4e33efaa3c820a47896b3b69b859f00fbebcc2477ae0dc8d796f3eab6ed4b17a
5
5
  SHA512:
6
- metadata.gz: bf8a1d4cc12a450424668ddf201f7cdf20293e8cca5c4269f6a405bbd91718b40e2e6011537cd39643728510fd75b0e51e05f84dcebf85ea5bcadb3a637f6ce2
7
- data.tar.gz: 9ae41cf5a5f711c9a795ca7aeb6e67bc31c57c2926e05bd898b3645c4e4be6acfd1e94eafbbc687a6c0bb8bda512e0cbaa77a6c01f4c6a1b360149f8effcb231
6
+ metadata.gz: 52bdf038de5e035b2825c870d0f9912e93aa27254c464c2b55c5dac3864d429e05455b283fba81105cd03c0ba837b1d4aaf957d89af8b82f359c514bb0093c76
7
+ data.tar.gz: fb6f1cd85a31526f692be5d5a4201074decaf2f82d1d40fec3bee9f24b43683c9300bc707c2ea918f7dfd73b1bfbcd92db4b70aabf05a3c65e0092c8ad5fe359
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.11.4'
9
9
  spec.authors = ['Glia TechMovers']
10
10
  spec.email = ['techmovers@glia.com']
11
11
 
data/lib/glia/errors.rb CHANGED
@@ -12,7 +12,7 @@ module Glia
12
12
  def self.from_dry_validation_result(result, custom_error_map = {})
13
13
  dry_validation_version = Gem.loaded_specs['dry-validation'].version
14
14
  if dry_validation_version < Gem::Version.new('1.0')
15
- Mapper.from_dry_validation_result(result.output, result.messages, custom_error_map)
15
+ Mapper.from_dry_validation_result(result.output, result.errors, custom_error_map)
16
16
  elsif dry_validation_version <= Gem::Version.new('1.6')
17
17
  Mapper.from_dry_validation_result(result.to_h, result.errors.to_h, custom_error_map)
18
18
  else
@@ -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,20 +181,33 @@ 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
- type: LIMIT_EXCEEDED_ERROR,
182
- ref: create_ref(LIMIT_EXCEEDED_ERROR),
187
+ type: RESOURCE_LIMIT_EXCEEDED_ERROR,
188
+ ref: create_ref(RESOURCE_LIMIT_EXCEEDED_ERROR),
183
189
  message: message || "#{Naming.humanize(resource)} count must not exceed #{max}",
184
190
  error_details: { resource: resource, max: max }
185
191
  )
186
192
  end
187
193
  end
188
194
 
195
+ class ResourceMinimumNotReachedError < Error
196
+ def initialize(resource:, min:, message: nil)
197
+ Naming.assert_snake_case(resource)
198
+
199
+ super(
200
+ type: RESOURCE_MINIMUM_NOT_REACHED,
201
+ ref: create_ref(RESOURCE_MINIMUM_NOT_REACHED),
202
+ message: message || "#{Naming.humanize(resource)} count must reach at least #{min}",
203
+ error_details: { resource: resource, min: min }
204
+ )
205
+ end
206
+ end
207
+
189
208
  class ResourceAlreadyExistsError < Error
190
209
  def initialize(resource:, message: nil)
191
- assert_snake_case(resource)
210
+ Naming.assert_snake_case(resource)
192
211
 
193
212
  super(
194
213
  type: RESOURCE_ALREADY_EXISTS_ERROR,
@@ -201,8 +220,8 @@ module Glia
201
220
 
202
221
  class InvalidResourceStateError < Error
203
222
  def initialize(resource:, state:, message: nil)
204
- assert_snake_case(resource)
205
- assert_snake_case(state)
223
+ Naming.assert_snake_case(resource)
224
+ Naming.assert_snake_case(state)
206
225
 
207
226
  super(
208
227
  type: INVALID_RESOURCE_STATE_ERROR,
@@ -322,6 +341,76 @@ module Glia
322
341
  )
323
342
  end
324
343
  end
344
+
345
+ class HeadersValidationError < Error
346
+ def initialize(error_details:, message: nil)
347
+ raise ArgumentError, 'At least 1 error detail is required' if error_details.keys.count.zero?
348
+
349
+ error_details.each_value do |value|
350
+ raise ArgumentError, 'error_details values must be lists' unless value.is_a?(Array)
351
+ end
352
+
353
+ error_details.each_key { |key| Naming.assert_header(key) }
354
+
355
+ super(
356
+ type: HEADERS_VALIDATION_ERROR,
357
+ ref: create_ref(HEADERS_VALIDATION_ERROR),
358
+ message: message || 'Headers are invalid',
359
+ error_details: error_details
360
+ )
361
+ end
362
+ end
363
+
364
+ class FacebookAccessTokenPermissionsError < Error
365
+ def initialize(message: nil)
366
+ super(
367
+ type: FACEBOOK_ACCESS_TOKEN_PERMISSIONS_ERROR,
368
+ ref: create_ref(FACEBOOK_ACCESS_TOKEN_PERMISSIONS_ERROR),
369
+ message: message || 'Access token does not have sufficient permissions'
370
+ )
371
+ end
372
+ end
373
+
374
+ class FacebookAccessTokenNotPermanentError < Error
375
+ def initialize(message: nil)
376
+ super(
377
+ type: FACEBOOK_ACCESS_TOKEN_NOT_PERMANENT_ERROR,
378
+ ref: create_ref(FACEBOOK_ACCESS_TOKEN_NOT_PERMANENT_ERROR),
379
+ message: message || 'Access token does not yield permanent access tokens'
380
+ )
381
+ end
382
+ end
383
+
384
+ class OAuthCodeExpiredError < Error
385
+ def initialize(message: nil)
386
+ super(
387
+ type: OAUTH_CODE_EXPIRED_ERROR,
388
+ ref: create_ref(OAUTH_CODE_EXPIRED_ERROR),
389
+ message: message || 'OAuth code has expired'
390
+ )
391
+ end
392
+ end
393
+
394
+ class OAuthCodeAlreadyUsedError < Error
395
+ def initialize(message: nil)
396
+ super(
397
+ type: OAUTH_CODE_ALREADY_USED_ERROR,
398
+ ref: create_ref(OAUTH_CODE_ALREADY_USED_ERROR),
399
+ message: message || 'OAuth code has already been used'
400
+ )
401
+ end
402
+ end
403
+
404
+ class AppleBusinessChatBusinessUsedByOtherSiteError < Error
405
+ def initialize(message: nil)
406
+ super(
407
+ type: APPLE_BUSINESS_CHAT_BUSINESS_USED_BY_OTHER_SITE_ERROR,
408
+ ref: create_ref(APPLE_BUSINESS_CHAT_BUSINESS_USED_BY_OTHER_SITE_ERROR),
409
+ message: message || 'Business is already used by a channel on another site'
410
+ )
411
+ end
412
+ end
413
+
325
414
  # rubocop:enable Style/Documentation
326
415
  end
327
416
  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}"
@@ -14,7 +14,8 @@ module Glia
14
14
  RESOURCE_NOT_FOUND_ERROR = 'resource_not_found_error'
15
15
  NOT_VERIFIED_ERROR = 'not_verified_error'
16
16
  REMAINING_ASSOCIATION_ERROR = 'remaining_association_error'
17
- LIMIT_EXCEEDED_ERROR = 'limit_exceeded_error'
17
+ RESOURCE_LIMIT_EXCEEDED_ERROR = 'resource_limit_exceeded_error'
18
+ RESOURCE_MINIMUM_NOT_REACHED = 'resource_minimum_not_reached'
18
19
  RESOURCE_ALREADY_EXISTS_ERROR = 'resource_already_exists_error'
19
20
  INVALID_RESOURCE_STATE_ERROR = 'invalid_resource_state_error'
20
21
  AUTHORIZATION_ERROR = 'authorization_error'
@@ -28,6 +29,13 @@ module Glia
28
29
  TELEPHONY_PROVIDER_QUEUE_LIMIT_EXCEEDED_ERROR = 'telephony_provider_queue_limit_exceeded_error'
29
30
  TWILIO_MESSAGING_SERVICE_CONFIGURATION_ERROR = 'twilio_messaging_service_configuration_error'
30
31
  UNREACHABLE_DESTINATION_ERROR = 'unreachable_destination_error'
32
+ HEADERS_VALIDATION_ERROR = 'headers_validation_error'
33
+ FACEBOOK_ACCESS_TOKEN_PERMISSIONS_ERROR = 'facebook_access_token_permissions_error'
34
+ FACEBOOK_ACCESS_TOKEN_NOT_PERMANENT_ERROR = 'facebook_access_token_not_permanent_error'
35
+ OAUTH_CODE_EXPIRED_ERROR = 'oauth_code_expired_error'
36
+ OAUTH_CODE_ALREADY_USED_ERROR = 'oauth_code_already_used_error'
37
+ APPLE_BUSINESS_CHAT_BUSINESS_USED_BY_OTHER_SITE_ERROR =
38
+ 'apple_business_chat_business_used_by_other_site_error'
31
39
 
32
40
  # Server errors
33
41
  INTERNAL_SERVER_ERROR = 'internal_server_error'
@@ -13,8 +13,8 @@ module Glia
13
13
  upcase_first(result)
14
14
  end
15
15
 
16
- ABBREVIATIONS = %w[id uuid saml sip sms mms].freeze
17
- PLURAL_ABBREVIATIONS = %w[ids uuids].freeze
16
+ ABBREVIATIONS = %w[id uuid saml sip sms mms uri url].freeze
17
+ PLURAL_ABBREVIATIONS = %w[ids uuids uris urls].freeze
18
18
 
19
19
  private_class_method def self.upcase_if_abbreviation(value)
20
20
  if ABBREVIATIONS.include?(value)
@@ -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.11.4
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-08-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ''
14
14
  email: