glia-errors 0.7.0 → 0.8.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: f938565ae0608918f0808c950e1d2621f7d8ef2d347cb9146a37fc1af461a519
4
- data.tar.gz: 7d8d9672987fe83c77884532e052adee18e3e980462176b6482dd1a41fb755ec
3
+ metadata.gz: 5c7f5990ad3700b39cf8e730592d7a0e1bb41968015c54c648f341e329679852
4
+ data.tar.gz: 56963475888904d6d252deb42667536caeb1a7ff96c7bbb35d5204395f60723d
5
5
  SHA512:
6
- metadata.gz: f09300cb765f7ce0fe8d57cce7f8259303acd5dec9ffd61a36307ba0afb9d89c17ca95eb8010526a442ab0028da8fc9c61821f7fbe3cd5727c5d0df2a33e3821
7
- data.tar.gz: 8208ee1f6c9e00975df486a1d8fb3f1457f38a576970f15485191f9639340b0ff5247dbcf527f2474ef1f0696ff519994985e9917c91949c33c9e6bcbc9a3c42
6
+ metadata.gz: 7a09bd918e4be8fb7463523004703cf8d94e1a709f70f545f3b8f1d51384c5ba9a2be31c0a0b633042b9eec610003251b1fceb122d266c667ff18f4789487ef1
7
+ data.tar.gz: 4749bb8358fc6a1dc3f8940ae9ef5424cfdb65bef2361a529ea591890e86a8ec43a1b33207be110e7404c0ae270bd0cb197bfe11d744583ef698cce02cbbc3fe
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.7.0'
8
+ spec.version = '0.8.0'
9
9
  spec.authors = ['Glia TechMovers']
10
10
  spec.email = ['techmovers@glia.com']
11
11
 
@@ -19,7 +19,7 @@ module Glia
19
19
  super(
20
20
  type: INVALID_NUMBER_ERROR,
21
21
  ref: create_ref(INVALID_NUMBER_ERROR),
22
- message: message || "#{humanize(field)} value is invalid"
22
+ message: message || "#{Naming.humanize(field)} value is invalid"
23
23
  )
24
24
  end
25
25
  end
@@ -29,7 +29,7 @@ module Glia
29
29
  super(
30
30
  type: INVALID_VALUE_ERROR,
31
31
  ref: create_ref(INVALID_VALUE_ERROR),
32
- message: message || "#{humanize(field)} value is invalid"
32
+ message: message || "#{Naming.humanize(field)} value is invalid"
33
33
  )
34
34
  end
35
35
  end
@@ -39,7 +39,7 @@ module Glia
39
39
  super(
40
40
  type: INVALID_LENGTH_ERROR,
41
41
  ref: create_ref(INVALID_LENGTH_ERROR),
42
- message: message || "#{humanize(field)} length is invalid"
42
+ message: message || "#{Naming.humanize(field)} length is invalid"
43
43
  )
44
44
  end
45
45
  end
@@ -54,13 +54,34 @@ module Glia
54
54
 
55
55
  def initialize(field:, format: nil, message: nil)
56
56
  default_message =
57
- format ? "has invalid format, required format is #{format}" : 'has invalid format'
57
+ if format
58
+ "has invalid format, required format is #{humanize_format(format)}"
59
+ else
60
+ 'has invalid format'
61
+ end
58
62
  super(
59
63
  type: INVALID_FORMAT_ERROR,
60
64
  ref: create_ref(INVALID_FORMAT_ERROR),
61
- message: message || "#{humanize(field)} #{default_message}"
65
+ message: message || "#{Naming.humanize(field)} #{default_message}"
62
66
  )
63
67
  end
68
+
69
+ private
70
+
71
+ def humanize_format(format)
72
+ case format
73
+ when Formats::DATE
74
+ 'ISO-8601 date'
75
+ when Formats::TIME
76
+ 'ISO-8601 time'
77
+ when Formats::DATE_TIME
78
+ 'ISO-8601 date and time'
79
+ when Formats::UUID
80
+ 'UUID'
81
+ else
82
+ raise 'Unexpected InvalidFormatError format'
83
+ end
84
+ end
64
85
  end
65
86
 
66
87
  class InvalidTypeError < Error
@@ -77,7 +98,7 @@ module Glia
77
98
  super(
78
99
  type: INVALID_TYPE_ERROR,
79
100
  ref: create_ref(INVALID_TYPE_ERROR),
80
- message: message || "#{humanize(field)} must be of type #{type}",
101
+ message: message || "#{Naming.humanize(field)} must be of type #{type}",
81
102
  error_details: { type: type }
82
103
  )
83
104
  end
@@ -88,7 +109,7 @@ module Glia
88
109
  super(
89
110
  type: MISSING_VALUE_ERROR,
90
111
  ref: create_ref(MISSING_VALUE_ERROR),
91
- message: message || "#{humanize(field)} is missing"
112
+ message: message || "#{Naming.humanize(field)} is missing"
92
113
  )
93
114
  end
94
115
  end
@@ -98,7 +119,7 @@ module Glia
98
119
  super(
99
120
  type: UNKNOWN_ERROR,
100
121
  ref: create_ref(UNKNOWN_ERROR),
101
- message: message || "#{humanize(field)} validation failed with unknown error"
122
+ message: message || "#{Naming.humanize(field)} validation failed with unknown error"
102
123
  )
103
124
  end
104
125
  end
@@ -110,7 +131,7 @@ module Glia
110
131
  super(
111
132
  type: RESOURCE_NOT_FOUND_ERROR,
112
133
  ref: create_ref(RESOURCE_NOT_FOUND_ERROR),
113
- message: message || "#{humanize(resource)} not found",
134
+ message: message || "#{Naming.humanize(resource)} not found",
114
135
  error_details: { resource: resource }
115
136
  )
116
137
  end
@@ -123,7 +144,7 @@ module Glia
123
144
  super(
124
145
  type: NOT_VERIFIED_ERROR,
125
146
  ref: create_ref(NOT_VERIFIED_ERROR),
126
- message: message || "#{humanize(resource)} is not verified",
147
+ message: message || "#{Naming.humanize(resource)} is not verified",
127
148
  error_details: { resource: resource }
128
149
  )
129
150
  end
@@ -136,25 +157,25 @@ module Glia
136
157
 
137
158
  default_message =
138
159
  "cannot be modified/deleted because it is associated to one or more #{
139
- humanize(associated_resource)
160
+ Naming.humanize(associated_resource)
140
161
  }(s)"
141
162
  super(
142
163
  type: REMAINING_ASSOCIATION_ERROR,
143
164
  ref: create_ref(REMAINING_ASSOCIATION_ERROR),
144
- message: message || "#{humanize(resource)} #{default_message}",
165
+ message: message || "#{Naming.humanize(resource)} #{default_message}",
145
166
  error_details: { resource: resource, associated_resource: associated_resource }
146
167
  )
147
168
  end
148
169
  end
149
170
 
150
- class LimitExceededError < Error
171
+ class ResourceLimitExceededError < Error
151
172
  def initialize(resource:, max:, message: nil)
152
173
  assert_snake_case(resource)
153
174
 
154
175
  super(
155
176
  type: LIMIT_EXCEEDED_ERROR,
156
177
  ref: create_ref(LIMIT_EXCEEDED_ERROR),
157
- message: message || "#{humanize(resource)} count must not exceed #{max}",
178
+ message: message || "#{Naming.humanize(resource)} count must not exceed #{max}",
158
179
  error_details: { resource: resource, max: max }
159
180
  )
160
181
  end
@@ -167,7 +188,7 @@ module Glia
167
188
  super(
168
189
  type: RESOURCE_ALREADY_EXISTS_ERROR,
169
190
  ref: create_ref(RESOURCE_ALREADY_EXISTS_ERROR),
170
- message: message || "#{humanize(resource)} already exists",
191
+ message: message || "#{Naming.humanize(resource)} already exists",
171
192
  error_details: { resource: resource }
172
193
  )
173
194
  end
@@ -181,7 +202,7 @@ module Glia
181
202
  super(
182
203
  type: INVALID_RESOURCE_STATE_ERROR,
183
204
  ref: create_ref(INVALID_RESOURCE_STATE_ERROR),
184
- message: message || "#{humanize(resource)} is in invalid state: #{state}",
205
+ message: message || "#{Naming.humanize(resource)} is in invalid state: #{state}",
185
206
  error_details: { resource: resource, state: state }
186
207
  )
187
208
  end
@@ -206,6 +227,26 @@ module Glia
206
227
  )
207
228
  end
208
229
  end
230
+
231
+ class RouteNotFoundError < Error
232
+ def initialize(message: nil)
233
+ super(
234
+ type: ROUTE_NOT_FOUND_ERROR,
235
+ ref: create_ref(ROUTE_NOT_FOUND_ERROR),
236
+ message: message || 'Route not found'
237
+ )
238
+ end
239
+ end
240
+
241
+ class MalformedInputError < Error
242
+ def initialize(message: nil)
243
+ super(
244
+ type: MALFORMED_INPUT_ERROR,
245
+ ref: create_ref(MALFORMED_INPUT_ERROR),
246
+ message: message || 'Request is malformed'
247
+ )
248
+ end
249
+ end
209
250
  # rubocop:enable Style/Documentation
210
251
  end
211
252
  end
@@ -1,5 +1,7 @@
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
@@ -43,12 +45,6 @@ module Glia
43
45
  [TrueClass, FalseClass, String, Integer, Float, Symbol].include?(details.class)
44
46
  end
45
47
 
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
48
  def assert_snake_case(value)
53
49
  return if value.to_s.match(SNAKE_CASE_REGEX)
54
50
 
@@ -19,6 +19,8 @@ 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'
22
24
 
23
25
  # Server errors
24
26
  INTERNAL_SERVER_ERROR = 'internal_server_error'
@@ -0,0 +1,34 @@
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
+ end
33
+ end
34
+ 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.7.0
4
+ version: 0.8.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-05 00:00:00.000000000 Z
11
+ date: 2021-03-12 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: