glia-errors 0.6.1 → 0.11.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: f3f1709fffc93f8968a42d643b4efc6fd300ab47de475c21f5632b804085d07d
4
+ data.tar.gz: 1b93f359b7083f4a5c9a8776c89d4f7bb4bcac2f419ebec7abb4ef025d0e3573
5
5
  SHA512:
6
- metadata.gz: fcf46277d4d7f2368999acab163f89e192d76ca0db527e94c39fdbcefe6b4bdf83dd2e6a116eef2eb2568e0a4d005f86dc06729925aa50b1dc9e050564d62093
7
- data.tar.gz: '04281d7946a62f546d3a2e4474336289a83142a2283a622a3abe13988f3d29bf24b66ff1e9aba02a5ce1043cd5232fc262138d1ee061a283e6d4b31a1f13ad98'
6
+ metadata.gz: 3bddb2518cbaf055d1ad9dc75f44f7d4eab2ef6a43506af2c24d2a41fd239bf1790d14069f73895aedc04e3beebe8ec83272d318d254e5c6ecfff50e429bb40d
7
+ data.tar.gz: c2b84141ccabb62b3da2a1875f83d679a60ee39d420bd77b222c508bd5f07234e31e2224855d3f2fdf9bb0535b173df58f19540cd63f37ba8f7e9e274c3547b1
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.11.0'
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,10 +5,16 @@ 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
- ref: "https://example.com/errors/#{INPUT_VALIDATION_ERROR}.html",
11
- message: message,
16
+ ref: create_ref(INPUT_VALIDATION_ERROR),
17
+ message: message || 'Input is invalid',
12
18
  error_details: error_details
13
19
  )
14
20
  end
@@ -18,8 +24,8 @@ module Glia
18
24
  def initialize(field:, message: nil)
19
25
  super(
20
26
  type: INVALID_NUMBER_ERROR,
21
- ref: "https://example.com/errors/#{INVALID_NUMBER_ERROR}.html",
22
- message: message || "#{humanize(field)} value is invalid"
27
+ ref: create_ref(INVALID_NUMBER_ERROR),
28
+ message: message || "#{Naming.humanize(field)} value is invalid"
23
29
  )
24
30
  end
25
31
  end
@@ -28,8 +34,8 @@ module Glia
28
34
  def initialize(field:, message: nil)
29
35
  super(
30
36
  type: INVALID_VALUE_ERROR,
31
- ref: "https://example.com/errors/#{INVALID_VALUE_ERROR}.html",
32
- message: message || "#{humanize(field)} value is invalid"
37
+ ref: create_ref(INVALID_VALUE_ERROR),
38
+ message: message || "#{Naming.humanize(field)} value is invalid"
33
39
  )
34
40
  end
35
41
  end
@@ -38,8 +44,8 @@ module Glia
38
44
  def initialize(field:, message: nil)
39
45
  super(
40
46
  type: INVALID_LENGTH_ERROR,
41
- ref: "https://example.com/errors/#{INVALID_LENGTH_ERROR}.html",
42
- message: message || "#{humanize(field)} length is invalid"
47
+ ref: create_ref(INVALID_LENGTH_ERROR),
48
+ message: message || "#{Naming.humanize(field)} length is invalid"
43
49
  )
44
50
  end
45
51
  end
@@ -54,13 +60,34 @@ module Glia
54
60
 
55
61
  def initialize(field:, format: nil, message: nil)
56
62
  default_message =
57
- format ? "has invalid format, required format is #{format}" : 'has invalid format'
63
+ if format
64
+ "has invalid format, required format is #{humanize_format(format)}"
65
+ else
66
+ 'has invalid format'
67
+ end
58
68
  super(
59
69
  type: INVALID_FORMAT_ERROR,
60
- ref: "https://example.com/errors/#{INVALID_FORMAT_ERROR}.html",
61
- message: message || "#{humanize(field)} #{default_message}"
70
+ ref: create_ref(INVALID_FORMAT_ERROR),
71
+ message: message || "#{Naming.humanize(field)} #{default_message}"
62
72
  )
63
73
  end
74
+
75
+ private
76
+
77
+ def humanize_format(format)
78
+ case format
79
+ when Formats::DATE
80
+ 'ISO-8601 date'
81
+ when Formats::TIME
82
+ 'ISO-8601 time'
83
+ when Formats::DATE_TIME
84
+ 'ISO-8601 date and time'
85
+ when Formats::UUID
86
+ 'UUID'
87
+ else
88
+ raise 'Unexpected InvalidFormatError format'
89
+ end
90
+ end
64
91
  end
65
92
 
66
93
  class InvalidTypeError < Error
@@ -76,8 +103,8 @@ module Glia
76
103
  def initialize(field:, type:, message: nil)
77
104
  super(
78
105
  type: INVALID_TYPE_ERROR,
79
- ref: "https://example.com/errors/#{INVALID_TYPE_ERROR}.html",
80
- message: message || "#{humanize(field)} must be of type #{type}",
106
+ ref: create_ref(INVALID_TYPE_ERROR),
107
+ message: message || "#{Naming.humanize(field)} must be of type #{type}",
81
108
  error_details: { type: type }
82
109
  )
83
110
  end
@@ -87,30 +114,35 @@ module Glia
87
114
  def initialize(field:, message: nil)
88
115
  super(
89
116
  type: MISSING_VALUE_ERROR,
90
- ref: "https://example.com/errors/#{MISSING_VALUE_ERROR}.html",
91
- message: message || "#{humanize(field)} is missing"
117
+ ref: create_ref(MISSING_VALUE_ERROR),
118
+ message: message || "#{Naming.humanize(field)} is missing"
92
119
  )
93
120
  end
94
121
  end
95
122
 
96
123
  class UnknownError < Error
97
- def initialize(field:, message: nil)
124
+ def initialize(field: nil, message: nil)
98
125
  super(
99
126
  type: UNKNOWN_ERROR,
100
- ref: "https://example.com/errors/#{UNKNOWN_ERROR}.html",
101
- message: message || "#{humanize(field)} validation failed with unknown error"
127
+ ref: create_ref(UNKNOWN_ERROR),
128
+ message:
129
+ if field
130
+ message || "#{Naming.humanize(field)} validation failed with unknown error"
131
+ else
132
+ message || 'Failed with unknown error'
133
+ end
102
134
  )
103
135
  end
104
136
  end
105
137
 
106
138
  class ResourceNotFoundError < Error
107
139
  def initialize(resource:, message: nil)
108
- assert_snake_case(resource)
140
+ Naming.assert_snake_case(resource)
109
141
 
110
142
  super(
111
143
  type: RESOURCE_NOT_FOUND_ERROR,
112
- ref: "https://example.com/errors/#{RESOURCE_NOT_FOUND_ERROR}.html",
113
- message: message || "#{humanize(resource)} not found",
144
+ ref: create_ref(RESOURCE_NOT_FOUND_ERROR),
145
+ message: message || "#{Naming.humanize(resource)} not found",
114
146
  error_details: { resource: resource }
115
147
  )
116
148
  end
@@ -118,12 +150,12 @@ module Glia
118
150
 
119
151
  class NotVerifiedError < Error
120
152
  def initialize(resource:, message: nil)
121
- assert_snake_case(resource)
153
+ Naming.assert_snake_case(resource)
122
154
 
123
155
  super(
124
156
  type: NOT_VERIFIED_ERROR,
125
- ref: "https://example.com/errors/#{NOT_VERIFIED_ERROR}.html",
126
- message: message || "#{humanize(resource)} is not verified",
157
+ ref: create_ref(NOT_VERIFIED_ERROR),
158
+ message: message || "#{Naming.humanize(resource)} is not verified",
127
159
  error_details: { resource: resource }
128
160
  )
129
161
  end
@@ -131,30 +163,30 @@ module Glia
131
163
 
132
164
  class RemainingAssociationError < Error
133
165
  def initialize(resource:, associated_resource:, message: nil)
134
- assert_snake_case(resource)
135
- assert_snake_case(associated_resource)
166
+ Naming.assert_snake_case(resource)
167
+ Naming.assert_snake_case(associated_resource)
136
168
 
137
169
  default_message =
138
170
  "cannot be modified/deleted because it is associated to one or more #{
139
- humanize(associated_resource)
171
+ Naming.humanize(associated_resource)
140
172
  }(s)"
141
173
  super(
142
174
  type: REMAINING_ASSOCIATION_ERROR,
143
- ref: "https://example.com/errors/#{REMAINING_ASSOCIATION_ERROR}.html",
144
- message: message || "#{humanize(resource)} #{default_message}",
175
+ ref: create_ref(REMAINING_ASSOCIATION_ERROR),
176
+ message: message || "#{Naming.humanize(resource)} #{default_message}",
145
177
  error_details: { resource: resource, associated_resource: associated_resource }
146
178
  )
147
179
  end
148
180
  end
149
181
 
150
- class LimitExceededError < Error
182
+ class ResourceLimitExceededError < Error
151
183
  def initialize(resource:, max:, message: nil)
152
- assert_snake_case(resource)
184
+ Naming.assert_snake_case(resource)
153
185
 
154
186
  super(
155
187
  type: LIMIT_EXCEEDED_ERROR,
156
- ref: "https://example.com/errors/#{LIMIT_EXCEEDED_ERROR}.html",
157
- message: message || "#{humanize(resource)} count must not exceed #{max}",
188
+ ref: create_ref(LIMIT_EXCEEDED_ERROR),
189
+ message: message || "#{Naming.humanize(resource)} count must not exceed #{max}",
158
190
  error_details: { resource: resource, max: max }
159
191
  )
160
192
  end
@@ -162,12 +194,12 @@ module Glia
162
194
 
163
195
  class ResourceAlreadyExistsError < Error
164
196
  def initialize(resource:, message: nil)
165
- assert_snake_case(resource)
197
+ Naming.assert_snake_case(resource)
166
198
 
167
199
  super(
168
200
  type: RESOURCE_ALREADY_EXISTS_ERROR,
169
- ref: "https://example.com/errors/#{RESOURCE_ALREADY_EXISTS_ERROR}.html",
170
- message: message || "#{humanize(resource)} already exists",
201
+ ref: create_ref(RESOURCE_ALREADY_EXISTS_ERROR),
202
+ message: message || "#{Naming.humanize(resource)} already exists",
171
203
  error_details: { resource: resource }
172
204
  )
173
205
  end
@@ -175,13 +207,13 @@ module Glia
175
207
 
176
208
  class InvalidResourceStateError < Error
177
209
  def initialize(resource:, state:, message: nil)
178
- assert_snake_case(resource)
179
- assert_snake_case(state)
210
+ Naming.assert_snake_case(resource)
211
+ Naming.assert_snake_case(state)
180
212
 
181
213
  super(
182
214
  type: INVALID_RESOURCE_STATE_ERROR,
183
- ref: "https://example.com/errors/#{INVALID_RESOURCE_STATE_ERROR}.html",
184
- message: message || "#{humanize(resource)} is in invalid state: #{state}",
215
+ ref: create_ref(INVALID_RESOURCE_STATE_ERROR),
216
+ message: message || "#{Naming.humanize(resource)} is in invalid state: #{state}",
185
217
  error_details: { resource: resource, state: state }
186
218
  )
187
219
  end
@@ -191,7 +223,7 @@ module Glia
191
223
  def initialize(message: nil)
192
224
  super(
193
225
  type: AUTHORIZATION_ERROR,
194
- ref: "https://example.com/errors/#{AUTHORIZATION_ERROR}.html",
226
+ ref: create_ref(AUTHORIZATION_ERROR),
195
227
  message: message || 'You do not have permissions to perform the action'
196
228
  )
197
229
  end
@@ -201,12 +233,120 @@ module Glia
201
233
  def initialize(message: nil)
202
234
  super(
203
235
  type: RECIPIENT_OPTED_OUT_ERROR,
204
- ref:
205
- 'https://docs.glia.com/glia-dev/reference/webhooks#example-engagementrequestfailure-event-with-fail_error',
236
+ ref: create_ref(RECIPIENT_OPTED_OUT_ERROR),
206
237
  message: message || 'Recipient has opted out'
207
238
  )
208
239
  end
209
240
  end
241
+
242
+ class RouteNotFoundError < Error
243
+ def initialize(message: nil)
244
+ super(
245
+ type: ROUTE_NOT_FOUND_ERROR,
246
+ ref: create_ref(ROUTE_NOT_FOUND_ERROR),
247
+ message: message || 'Route not found'
248
+ )
249
+ end
250
+ end
251
+
252
+ class MalformedInputError < Error
253
+ def initialize(message: nil)
254
+ super(
255
+ type: MALFORMED_INPUT_ERROR,
256
+ ref: create_ref(MALFORMED_INPUT_ERROR),
257
+ message: message || 'Request is malformed'
258
+ )
259
+ end
260
+ end
261
+
262
+ class CarrierError < Error
263
+ def initialize(message: nil)
264
+ super(
265
+ type: CARRIER_ERROR,
266
+ ref: create_ref(CARRIER_ERROR),
267
+ message: message || 'Downstream carrier issue occurred'
268
+ )
269
+ end
270
+ end
271
+
272
+ class GeographicPermissionError < Error
273
+ def initialize(message: nil)
274
+ super(
275
+ type: GEOGRAPHIC_PERMISSION_ERROR,
276
+ ref: create_ref(GEOGRAPHIC_PERMISSION_ERROR),
277
+ message: message || 'Insufficient permissions for geographic region'
278
+ )
279
+ end
280
+ end
281
+
282
+ class MessageBlockedError < Error
283
+ def initialize(message: nil)
284
+ super(
285
+ type: MESSAGE_BLOCKED_ERROR,
286
+ ref: create_ref(MESSAGE_BLOCKED_ERROR),
287
+ message: message || 'Message blocked or filtered'
288
+ )
289
+ end
290
+ end
291
+
292
+ class TelephonyProviderRateLimitExceededError < Error
293
+ def initialize(message: nil)
294
+ super(
295
+ type: TELEPHONY_PROVIDER_RATE_LIMIT_EXCEEDED_ERROR,
296
+ ref: create_ref(TELEPHONY_PROVIDER_RATE_LIMIT_EXCEEDED_ERROR),
297
+ message: message || 'Telephony provider message send rate limit exceeded'
298
+ )
299
+ end
300
+ end
301
+
302
+ class TelephonyProviderQueueLimitExceededError < Error
303
+ def initialize(message: nil)
304
+ super(
305
+ type: TELEPHONY_PROVIDER_QUEUE_LIMIT_EXCEEDED_ERROR,
306
+ ref: create_ref(TELEPHONY_PROVIDER_QUEUE_LIMIT_EXCEEDED_ERROR),
307
+ message: message || 'Telephony provider message send queue is full'
308
+ )
309
+ end
310
+ end
311
+
312
+ class TwilioMessagingServiceConfigurationError < Error
313
+ def initialize(message: nil)
314
+ super(
315
+ type: TWILIO_MESSAGING_SERVICE_CONFIGURATION_ERROR,
316
+ ref: create_ref(TWILIO_MESSAGING_SERVICE_CONFIGURATION_ERROR),
317
+ message: message || 'Invalid Twilio Messaging Service configuration'
318
+ )
319
+ end
320
+ end
321
+
322
+ class UnreachableDestinationError < Error
323
+ def initialize(message: nil)
324
+ super(
325
+ type: UNREACHABLE_DESTINATION_ERROR,
326
+ ref: create_ref(UNREACHABLE_DESTINATION_ERROR),
327
+ message: message || 'Destination is unreachable'
328
+ )
329
+ end
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
210
350
  # rubocop:enable Style/Documentation
211
351
  end
212
352
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './naming'
4
+
3
5
  module Glia
4
6
  module Errors
5
7
  # Base error
6
8
  class Error
7
- SNAKE_CASE_REGEX = /^[a-z0-9]+(_[a-z0-9]+)*$/.freeze
8
9
  attr_reader :type, :ref, :message, :error_details
9
10
 
10
11
  def initialize(type:, ref:, message: nil, error_details: nil)
@@ -43,16 +44,9 @@ module Glia
43
44
  [TrueClass, FalseClass, String, Integer, Float, Symbol].include?(details.class)
44
45
  end
45
46
 
46
- # Converts from camel_case to capitalized more human readable value
47
- # first_name => "First name"
48
- def humanize(value)
49
- value.to_s.capitalize.gsub('_', ' ')
50
- end
51
-
52
- def assert_snake_case(value)
53
- return if value.to_s.match(SNAKE_CASE_REGEX)
54
-
55
- raise ArgumentError, "Expected '#{value}' to be in snake case"
47
+ def create_ref(type)
48
+ fragment = type.gsub('_', '-')
49
+ "https://docs.glia.com/glia-dev/reference/errors##{fragment}"
56
50
  end
57
51
  end
58
52
  end
@@ -19,6 +19,16 @@ module Glia
19
19
  INVALID_RESOURCE_STATE_ERROR = 'invalid_resource_state_error'
20
20
  AUTHORIZATION_ERROR = 'authorization_error'
21
21
  RECIPIENT_OPTED_OUT_ERROR = 'recipient_opted_out_error'
22
+ ROUTE_NOT_FOUND_ERROR = 'route_not_found_error'
23
+ MALFORMED_INPUT_ERROR = 'malformed_input_error'
24
+ CARRIER_ERROR = 'carrier_error'
25
+ GEOGRAPHIC_PERMISSION_ERROR = 'geographic_permission_error'
26
+ MESSAGE_BLOCKED_ERROR = 'message_blocked_error'
27
+ TELEPHONY_PROVIDER_RATE_LIMIT_EXCEEDED_ERROR = 'telephony_provider_rate_limit_exceeded_error'
28
+ TELEPHONY_PROVIDER_QUEUE_LIMIT_EXCEEDED_ERROR = 'telephony_provider_queue_limit_exceeded_error'
29
+ TWILIO_MESSAGING_SERVICE_CONFIGURATION_ERROR = 'twilio_messaging_service_configuration_error'
30
+ UNREACHABLE_DESTINATION_ERROR = 'unreachable_destination_error'
31
+ HEADERS_VALIDATION_ERROR = 'headers_validation_error'
22
32
 
23
33
  # Server errors
24
34
  INTERNAL_SERVER_ERROR = 'internal_server_error'
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glia
4
+ module Errors
5
+ # Utilities for variable and resouce names
6
+ module Naming
7
+ # Converts from camel_case to more human readable value
8
+ # first_name => "First name"
9
+ # site_id => "Site ID"
10
+ def self.humanize(value)
11
+ result = value.to_s.split('_').map { |word| upcase_if_abbreviation(word) }.join(' ')
12
+
13
+ upcase_first(result)
14
+ end
15
+
16
+ ABBREVIATIONS = %w[id uuid saml sip sms mms].freeze
17
+ PLURAL_ABBREVIATIONS = %w[ids uuids].freeze
18
+
19
+ private_class_method def self.upcase_if_abbreviation(value)
20
+ if ABBREVIATIONS.include?(value)
21
+ value.upcase
22
+ elsif PLURAL_ABBREVIATIONS.include?(value)
23
+ value[0..-2].upcase.concat('s')
24
+ else
25
+ value
26
+ end
27
+ end
28
+
29
+ private_class_method def self.upcase_first(value)
30
+ value[0].upcase.concat(value[1..-1])
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
48
+ end
49
+ end
50
+ 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.11.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-04-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ''
14
14
  email:
@@ -37,6 +37,7 @@ files:
37
37
  - lib/glia/errors/error.rb
38
38
  - lib/glia/errors/error_types.rb
39
39
  - lib/glia/errors/mapper.rb
40
+ - lib/glia/errors/naming.rb
40
41
  - lib/glia/errors/server_errors.rb
41
42
  homepage:
42
43
  licenses: