glia-errors 0.0.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -2
- data/README.md +14 -16
- data/gemfiles/dry_validation_v0.gemfile +1 -1
- data/gemfiles/dry_validation_v1.gemfile +1 -1
- data/glia-errors.gemspec +1 -1
- data/lib/glia/errors.rb +2 -1
- data/lib/glia/errors/client_errors.rb +212 -0
- data/lib/glia/errors/error.rb +9 -1
- data/lib/glia/errors/error_types.rb +13 -0
- data/lib/glia/errors/mapper.rb +25 -27
- data/lib/glia/errors/server_errors.rb +27 -0
- metadata +6 -12
- data/LICENSE +0 -21
- data/lib/glia/errors/validation_errors.rb +0 -115
- data/test_cases/invalid_format_error_case.json +0 -74
- data/test_cases/invalid_length_error_case.json +0 -106
- data/test_cases/invalid_nested_params_case.json +0 -77
- data/test_cases/invalid_number_error_case.json +0 -90
- data/test_cases/invalid_type_error_case.json +0 -98
- data/test_cases/invalid_value_error_case.json +0 -125
- data/test_cases/missing_value_error_case.json +0 -16
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Glia
|
4
|
+
module Errors
|
5
|
+
# rubocop:disable Style/Documentation
|
6
|
+
class InternalServerError < Error
|
7
|
+
def initialize(message: nil)
|
8
|
+
super(
|
9
|
+
type: INTERNAL_SERVER_ERROR,
|
10
|
+
ref: "https://example.com/errors/#{INTERNAL_SERVER_ERROR}.html",
|
11
|
+
message: message || 'Internal server error'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class ServiceUnavailableError < Error
|
17
|
+
def initialize(message: nil)
|
18
|
+
super(
|
19
|
+
type: SERVICE_UNAVAILABLE_ERROR,
|
20
|
+
ref: "https://example.com/errors/#{SERVICE_UNAVAILABLE_ERROR}.html",
|
21
|
+
message: message || 'Service unavailable'
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
# rubocop:enable Style/Documentation
|
26
|
+
end
|
27
|
+
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.
|
4
|
+
version: 0.6.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-
|
11
|
+
date: 2021-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ''
|
14
14
|
email:
|
@@ -22,28 +22,22 @@ files:
|
|
22
22
|
- ".prettierrc"
|
23
23
|
- ".rspec"
|
24
24
|
- ".rubocop.yml"
|
25
|
+
- ".ruby-version"
|
25
26
|
- ".travis.yml"
|
26
27
|
- Appraisals
|
27
28
|
- Gemfile
|
28
29
|
- Gemfile.lock
|
29
|
-
- LICENSE
|
30
30
|
- README.md
|
31
31
|
- Rakefile
|
32
32
|
- gemfiles/dry_validation_v0.gemfile
|
33
33
|
- gemfiles/dry_validation_v1.gemfile
|
34
34
|
- glia-errors.gemspec
|
35
35
|
- lib/glia/errors.rb
|
36
|
+
- lib/glia/errors/client_errors.rb
|
36
37
|
- lib/glia/errors/error.rb
|
37
38
|
- lib/glia/errors/error_types.rb
|
38
39
|
- lib/glia/errors/mapper.rb
|
39
|
-
- lib/glia/errors/
|
40
|
-
- test_cases/invalid_format_error_case.json
|
41
|
-
- test_cases/invalid_length_error_case.json
|
42
|
-
- test_cases/invalid_nested_params_case.json
|
43
|
-
- test_cases/invalid_number_error_case.json
|
44
|
-
- test_cases/invalid_type_error_case.json
|
45
|
-
- test_cases/invalid_value_error_case.json
|
46
|
-
- test_cases/missing_value_error_case.json
|
40
|
+
- lib/glia/errors/server_errors.rb
|
47
41
|
homepage:
|
48
42
|
licenses:
|
49
43
|
- MIT
|
@@ -63,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
57
|
- !ruby/object:Gem::Version
|
64
58
|
version: '0'
|
65
59
|
requirements: []
|
66
|
-
rubygems_version: 3.
|
60
|
+
rubygems_version: 3.1.4
|
67
61
|
signing_key:
|
68
62
|
specification_version: 4
|
69
63
|
summary: Glia REST API errors
|
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2020 Glia Inc.
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
@@ -1,115 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Glia
|
4
|
-
module Errors
|
5
|
-
# InputValidationError
|
6
|
-
class InputValidationError < Error
|
7
|
-
def initialize(error_details:, message: nil)
|
8
|
-
super(
|
9
|
-
type: INPUT_VALIDATION_ERROR,
|
10
|
-
ref: "https://example.com/errors/#{INPUT_VALIDATION_ERROR}.html",
|
11
|
-
message: message,
|
12
|
-
error_details: error_details
|
13
|
-
)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# InvalidNumberError
|
18
|
-
class InvalidNumberError < Error
|
19
|
-
def initialize(field:)
|
20
|
-
super(
|
21
|
-
type: INVALID_NUMBER_ERROR,
|
22
|
-
ref: "https://example.com/errors/#{INVALID_NUMBER_ERROR}.html",
|
23
|
-
message: "#{humanize(field)} is invalid"
|
24
|
-
)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# InvalidValueError
|
29
|
-
class InvalidValueError < Error
|
30
|
-
def initialize(field:)
|
31
|
-
super(
|
32
|
-
type: INVALID_VALUE_ERROR,
|
33
|
-
ref: "https://example.com/errors/#{INVALID_VALUE_ERROR}.html",
|
34
|
-
message: "#{humanize(field)} is invalid"
|
35
|
-
)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# InvalidLengthError
|
40
|
-
class InvalidLengthError < Error
|
41
|
-
def initialize(field:)
|
42
|
-
super(
|
43
|
-
type: INVALID_LENGTH_ERROR,
|
44
|
-
ref: "https://example.com/errors/#{INVALID_LENGTH_ERROR}.html",
|
45
|
-
message: "#{humanize(field)} length is invalid"
|
46
|
-
)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# InvalidFormatError
|
51
|
-
class InvalidFormatError < Error
|
52
|
-
class Formats
|
53
|
-
DATE_TIME = 'date_time'
|
54
|
-
DATE = 'date'
|
55
|
-
TIME = 'time'
|
56
|
-
UUID = 'uuid'
|
57
|
-
end
|
58
|
-
|
59
|
-
def initialize(field:, format: nil)
|
60
|
-
super(
|
61
|
-
type: INVALID_FORMAT_ERROR,
|
62
|
-
ref: "https://example.com/errors/#{INVALID_FORMAT_ERROR}.html",
|
63
|
-
message:
|
64
|
-
if format
|
65
|
-
"#{humanize(field)} has invalid format, required format is #{format}"
|
66
|
-
else
|
67
|
-
"#{humanize(field)} has invalid format"
|
68
|
-
end
|
69
|
-
)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
# InvalidTypeError
|
74
|
-
class InvalidTypeError < Error
|
75
|
-
class Types
|
76
|
-
STRING = 'string'
|
77
|
-
INTEGER = 'integer'
|
78
|
-
NUMBER = 'number'
|
79
|
-
BOOLEAN = 'boolean'
|
80
|
-
ARRAY = 'array'
|
81
|
-
OBJECT = 'object'
|
82
|
-
end
|
83
|
-
|
84
|
-
def initialize(field:, type:)
|
85
|
-
super(
|
86
|
-
type: INVALID_TYPE_ERROR,
|
87
|
-
ref: "https://example.com/errors/#{INVALID_TYPE_ERROR}.html",
|
88
|
-
message: "#{humanize(field)} must be of type #{type}"
|
89
|
-
)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# MissingValueError
|
94
|
-
class MissingValueError < Error
|
95
|
-
def initialize(field:)
|
96
|
-
super(
|
97
|
-
type: MISSING_VALUE_ERROR,
|
98
|
-
ref: "https://example.com/errors/#{MISSING_VALUE_ERROR}.html",
|
99
|
-
message: "#{humanize(field)} is missing"
|
100
|
-
)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# UnknownError
|
105
|
-
class UnknownError < Error
|
106
|
-
def initialize(field:)
|
107
|
-
super(
|
108
|
-
type: UNKNOWN_ERROR,
|
109
|
-
ref: "https://example.com/errors/#{UNKNOWN_ERROR}.html",
|
110
|
-
message: "#{humanize(field)} validation failed with unknown error"
|
111
|
-
)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"input": {
|
3
|
-
"invalid_format_abc_regex": "defg",
|
4
|
-
"invalid_format_date": "not date",
|
5
|
-
"invalid_format_date_time": "not date time",
|
6
|
-
"invalid_format_time": "not time",
|
7
|
-
"invalid_format_uuid": "not uuid",
|
8
|
-
"invalid_format_e164": "not phone number",
|
9
|
-
"invalid_format_phone_extension": "not phone extension",
|
10
|
-
"invalid_format_email": "not email"
|
11
|
-
},
|
12
|
-
"expectation": {
|
13
|
-
"type": "input_validation_error",
|
14
|
-
"ref": "https://example.com/errors/input_validation_error.html",
|
15
|
-
"error_details": {
|
16
|
-
"invalid_format_abc_regex": [
|
17
|
-
{
|
18
|
-
"type": "invalid_format_error",
|
19
|
-
"ref": "https://example.com/errors/invalid_format_error.html",
|
20
|
-
"message": "Invalid format abc regex has invalid format"
|
21
|
-
}
|
22
|
-
],
|
23
|
-
"invalid_format_date": [
|
24
|
-
{
|
25
|
-
"type": "invalid_format_error",
|
26
|
-
"ref": "https://example.com/errors/invalid_format_error.html",
|
27
|
-
"message": "Invalid format date has invalid format, required format is date"
|
28
|
-
}
|
29
|
-
],
|
30
|
-
"invalid_format_date_time": [
|
31
|
-
{
|
32
|
-
"type": "invalid_format_error",
|
33
|
-
"ref": "https://example.com/errors/invalid_format_error.html",
|
34
|
-
"message": "Invalid format date time has invalid format, required format is date_time"
|
35
|
-
}
|
36
|
-
],
|
37
|
-
"invalid_format_time": [
|
38
|
-
{
|
39
|
-
"type": "invalid_format_error",
|
40
|
-
"ref": "https://example.com/errors/invalid_format_error.html",
|
41
|
-
"message": "Invalid format time has invalid format, required format is time"
|
42
|
-
}
|
43
|
-
],
|
44
|
-
"invalid_format_uuid": [
|
45
|
-
{
|
46
|
-
"type": "invalid_format_error",
|
47
|
-
"ref": "https://example.com/errors/invalid_format_error.html",
|
48
|
-
"message": "Invalid format uuid has invalid format, required format is uuid"
|
49
|
-
}
|
50
|
-
],
|
51
|
-
"invalid_format_e164": [
|
52
|
-
{
|
53
|
-
"type": "invalid_format_error",
|
54
|
-
"ref": "https://example.com/errors/invalid_format_error.html",
|
55
|
-
"message": "Invalid format e164 has invalid format"
|
56
|
-
}
|
57
|
-
],
|
58
|
-
"invalid_format_phone_extension": [
|
59
|
-
{
|
60
|
-
"type": "invalid_format_error",
|
61
|
-
"ref": "https://example.com/errors/invalid_format_error.html",
|
62
|
-
"message": "Invalid format phone extension has invalid format"
|
63
|
-
}
|
64
|
-
],
|
65
|
-
"invalid_format_email": [
|
66
|
-
{
|
67
|
-
"type": "invalid_format_error",
|
68
|
-
"ref": "https://example.com/errors/invalid_format_error.html",
|
69
|
-
"message": "Invalid format email has invalid format"
|
70
|
-
}
|
71
|
-
]
|
72
|
-
}
|
73
|
-
}
|
74
|
-
}
|
@@ -1,106 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"input": {
|
3
|
-
"invalid_length_array_max_length_3": [1, 2, 3, 4],
|
4
|
-
"invalid_length_array_min_length_3": [1, 2],
|
5
|
-
"invalid_length_array_exact_length_3": [1, 2],
|
6
|
-
"invalid_length_array_range_length_1_2": [1, 2, 3],
|
7
|
-
"invalid_length_string_max_length_3": "abcd",
|
8
|
-
"invalid_length_string_min_length_3": "ab",
|
9
|
-
"invalid_length_string_exact_length_3": "ab",
|
10
|
-
"invalid_length_string_range_length_1_2": "abc",
|
11
|
-
"invalid_length_string_max_bytesize_3": "abcd",
|
12
|
-
"invalid_length_string_min_bytesize_3": "a",
|
13
|
-
"invalid_length_string_exact_bytesize_3": "ab",
|
14
|
-
"invalid_length_string_range_bytesize_1_2": "abc"
|
15
|
-
},
|
16
|
-
"expectation": {
|
17
|
-
"type": "input_validation_error",
|
18
|
-
"ref": "https://example.com/errors/input_validation_error.html",
|
19
|
-
"error_details": {
|
20
|
-
"invalid_length_array_max_length_3": [
|
21
|
-
{
|
22
|
-
"type": "invalid_length_error",
|
23
|
-
"ref": "https://example.com/errors/invalid_length_error.html",
|
24
|
-
"message": "Invalid length array max length 3 length is invalid"
|
25
|
-
}
|
26
|
-
],
|
27
|
-
"invalid_length_array_min_length_3": [
|
28
|
-
{
|
29
|
-
"type": "invalid_length_error",
|
30
|
-
"ref": "https://example.com/errors/invalid_length_error.html",
|
31
|
-
"message": "Invalid length array min length 3 length is invalid"
|
32
|
-
}
|
33
|
-
],
|
34
|
-
"invalid_length_array_exact_length_3": [
|
35
|
-
{
|
36
|
-
"type": "invalid_length_error",
|
37
|
-
"ref": "https://example.com/errors/invalid_length_error.html",
|
38
|
-
"message": "Invalid length array exact length 3 length is invalid"
|
39
|
-
}
|
40
|
-
],
|
41
|
-
"invalid_length_array_range_length_1_2": [
|
42
|
-
{
|
43
|
-
"type": "invalid_length_error",
|
44
|
-
"ref": "https://example.com/errors/invalid_length_error.html",
|
45
|
-
"message": "Invalid length array range length 1 2 length is invalid"
|
46
|
-
}
|
47
|
-
],
|
48
|
-
"invalid_length_string_max_length_3": [
|
49
|
-
{
|
50
|
-
"type": "invalid_length_error",
|
51
|
-
"ref": "https://example.com/errors/invalid_length_error.html",
|
52
|
-
"message": "Invalid length string max length 3 length is invalid"
|
53
|
-
}
|
54
|
-
],
|
55
|
-
"invalid_length_string_min_length_3": [
|
56
|
-
{
|
57
|
-
"type": "invalid_length_error",
|
58
|
-
"ref": "https://example.com/errors/invalid_length_error.html",
|
59
|
-
"message": "Invalid length string min length 3 length is invalid"
|
60
|
-
}
|
61
|
-
],
|
62
|
-
"invalid_length_string_exact_length_3": [
|
63
|
-
{
|
64
|
-
"type": "invalid_length_error",
|
65
|
-
"ref": "https://example.com/errors/invalid_length_error.html",
|
66
|
-
"message": "Invalid length string exact length 3 length is invalid"
|
67
|
-
}
|
68
|
-
],
|
69
|
-
"invalid_length_string_range_length_1_2": [
|
70
|
-
{
|
71
|
-
"type": "invalid_length_error",
|
72
|
-
"ref": "https://example.com/errors/invalid_length_error.html",
|
73
|
-
"message": "Invalid length string range length 1 2 length is invalid"
|
74
|
-
}
|
75
|
-
],
|
76
|
-
"invalid_length_string_max_bytesize_3": [
|
77
|
-
{
|
78
|
-
"type": "invalid_length_error",
|
79
|
-
"ref": "https://example.com/errors/invalid_length_error.html",
|
80
|
-
"message": "Invalid length string max bytesize 3 length is invalid"
|
81
|
-
}
|
82
|
-
],
|
83
|
-
"invalid_length_string_min_bytesize_3": [
|
84
|
-
{
|
85
|
-
"type": "invalid_length_error",
|
86
|
-
"ref": "https://example.com/errors/invalid_length_error.html",
|
87
|
-
"message": "Invalid length string min bytesize 3 length is invalid"
|
88
|
-
}
|
89
|
-
],
|
90
|
-
"invalid_length_string_exact_bytesize_3": [
|
91
|
-
{
|
92
|
-
"type": "invalid_length_error",
|
93
|
-
"ref": "https://example.com/errors/invalid_length_error.html",
|
94
|
-
"message": "Invalid length string exact bytesize 3 length is invalid"
|
95
|
-
}
|
96
|
-
],
|
97
|
-
"invalid_length_string_range_bytesize_1_2": [
|
98
|
-
{
|
99
|
-
"type": "invalid_length_error",
|
100
|
-
"ref": "https://example.com/errors/invalid_length_error.html",
|
101
|
-
"message": "Invalid length string range bytesize 1 2 length is invalid"
|
102
|
-
}
|
103
|
-
]
|
104
|
-
}
|
105
|
-
}
|
106
|
-
}
|
@@ -1,77 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"input": {
|
3
|
-
"object": {
|
4
|
-
"invalid_nested_object_value": "invalid"
|
5
|
-
},
|
6
|
-
"array": [
|
7
|
-
{
|
8
|
-
"invalid_nested_array_value": "invalid"
|
9
|
-
},
|
10
|
-
{
|
11
|
-
"invalid_nested_array_value": "valid"
|
12
|
-
},
|
13
|
-
{
|
14
|
-
"invalid_nested_array_value": "invalid"
|
15
|
-
}
|
16
|
-
]
|
17
|
-
},
|
18
|
-
"expectation": {
|
19
|
-
"type": "input_validation_error",
|
20
|
-
"ref": "https://example.com/errors/input_validation_error.html",
|
21
|
-
"error_details": {
|
22
|
-
"object": [
|
23
|
-
{
|
24
|
-
"type": "input_validation_error",
|
25
|
-
"ref": "https://example.com/errors/input_validation_error.html",
|
26
|
-
"error_details": {
|
27
|
-
"invalid_nested_object_value": [
|
28
|
-
{
|
29
|
-
"type": "invalid_value_error",
|
30
|
-
"ref": "https://example.com/errors/invalid_value_error.html",
|
31
|
-
"message": "Invalid nested object value is invalid"
|
32
|
-
}
|
33
|
-
]
|
34
|
-
}
|
35
|
-
}
|
36
|
-
],
|
37
|
-
"array": [
|
38
|
-
{
|
39
|
-
"type": "input_validation_error",
|
40
|
-
"ref": "https://example.com/errors/input_validation_error.html",
|
41
|
-
"error_details": {
|
42
|
-
"0": [
|
43
|
-
{
|
44
|
-
"type": "input_validation_error",
|
45
|
-
"ref": "https://example.com/errors/input_validation_error.html",
|
46
|
-
"error_details": {
|
47
|
-
"invalid_nested_array_value": [
|
48
|
-
{
|
49
|
-
"type": "invalid_value_error",
|
50
|
-
"ref": "https://example.com/errors/invalid_value_error.html",
|
51
|
-
"message": "Invalid nested array value is invalid"
|
52
|
-
}
|
53
|
-
]
|
54
|
-
}
|
55
|
-
}
|
56
|
-
],
|
57
|
-
"2": [
|
58
|
-
{
|
59
|
-
"type": "input_validation_error",
|
60
|
-
"ref": "https://example.com/errors/input_validation_error.html",
|
61
|
-
"error_details": {
|
62
|
-
"invalid_nested_array_value": [
|
63
|
-
{
|
64
|
-
"type": "invalid_value_error",
|
65
|
-
"ref": "https://example.com/errors/invalid_value_error.html",
|
66
|
-
"message": "Invalid nested array value is invalid"
|
67
|
-
}
|
68
|
-
]
|
69
|
-
}
|
70
|
-
}
|
71
|
-
]
|
72
|
-
}
|
73
|
-
}
|
74
|
-
]
|
75
|
-
}
|
76
|
-
}
|
77
|
-
}
|