human_error 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/human_error.rb +19 -1
- data/lib/human_error/configuration.rb +9 -1
- data/lib/human_error/error.rb +1 -1
- data/lib/human_error/error_code_directory.rb +1 -1
- data/lib/human_error/errors/authentication_error.rb +1 -1
- data/lib/human_error/errors/authentication_errors/duplicate_authentication_error.rb +1 -1
- data/lib/human_error/errors/authentication_errors/invalid_token_error.rb +1 -1
- data/lib/human_error/errors/authentication_errors/invalid_username_or_password_error.rb +1 -1
- data/lib/human_error/errors/crud_error.rb +1 -1
- data/lib/human_error/errors/crud_errors/resource_not_found_error.rb +1 -1
- data/lib/human_error/errors/crud_errors/resource_persistence_error.rb +1 -1
- data/lib/human_error/errors/request_error.rb +1 -1
- data/lib/human_error/knowledgebase_id_directory.rb +1 -1
- data/lib/human_error/utilities/string.rb +1 -1
- data/lib/human_error/version.rb +2 -2
- data/spec/lib/human_error/configuration_spec.rb +13 -1
- data/spec/lib/human_error/error_spec.rb +1 -1
- data/spec/lib/human_error/errors/authentication_errors/duplicate_authentication_error_spec.rb +1 -1
- data/spec/lib/human_error/errors/authentication_errors/invalid_token_error_spec.rb +1 -1
- data/spec/lib/human_error/errors/authentication_errors/invalid_username_or_password_error_spec.rb +1 -1
- data/spec/lib/human_error/errors/crud_errors/resource_not_found_error_spec.rb +1 -1
- data/spec/lib/human_error/errors/crud_errors/resource_persistence_error_spec.rb +1 -1
- data/spec/lib/human_error/errors/request_error_spec.rb +1 -1
- data/spec/lib/human_error_spec.rb +62 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40266972f0c31dc4ec24f48df7d66a46f19a89a1
|
4
|
+
data.tar.gz: 08b74ad4f42e1ee8fa9fe53a51baf0dae31861b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c64dc30c85833c395b3b2b2a943ca972ad1c94ceb68a1a2f71a2a68e5020f0d1f22794ae4bca3f87e1bdd31318c6c5424892260c37f0ef251614277406d3d5fa
|
7
|
+
data.tar.gz: a6b564f1d96f02b53e7ffb01aaa0864035b20465125267d5fc3eefb266465b1d89e14eda573145238084f0afd70aeaf6474aac63c77016c3f668a50d665d361c
|
data/lib/human_error.rb
CHANGED
@@ -2,5 +2,23 @@ require 'human_error/version'
|
|
2
2
|
require 'human_error/error'
|
3
3
|
require 'human_error/errors'
|
4
4
|
|
5
|
-
|
5
|
+
class HumanError
|
6
|
+
attr_accessor :configuration
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
self.configuration = Configuration.new
|
10
|
+
|
11
|
+
yield configuration if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
def fetch(error_type, **args)
|
15
|
+
Object.const_get("HumanError::Errors::#{error_type}").
|
16
|
+
new(configuration.to_h.merge(**args))
|
17
|
+
end
|
18
|
+
|
19
|
+
def raise(error_type, **args)
|
20
|
+
error = fetch(error_type, **args)
|
21
|
+
|
22
|
+
Kernel.raise error
|
23
|
+
end
|
6
24
|
end
|
@@ -1,8 +1,16 @@
|
|
1
|
-
|
1
|
+
class HumanError
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :api_version,
|
4
4
|
:api_error_documentation_url,
|
5
5
|
:knowledgebase_url
|
6
|
+
|
7
|
+
def to_h
|
8
|
+
{
|
9
|
+
knowledgebase_url: knowledgebase_url,
|
10
|
+
api_error_documentation_url: api_error_documentation_url,
|
11
|
+
api_version: api_version,
|
12
|
+
}
|
13
|
+
end
|
6
14
|
end
|
7
15
|
|
8
16
|
def self.configure
|
data/lib/human_error/error.rb
CHANGED
data/lib/human_error/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = '1.
|
1
|
+
class HumanError
|
2
|
+
VERSION = '1.4.0'
|
3
3
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rspectacular'
|
2
2
|
require 'human_error/configuration'
|
3
3
|
|
4
|
-
|
4
|
+
class HumanError
|
5
5
|
describe Configuration do
|
6
6
|
it 'can set the API version' do
|
7
7
|
configuration = Configuration.new
|
@@ -23,5 +23,17 @@ describe Configuration do
|
|
23
23
|
|
24
24
|
expect(configuration.knowledgebase_url).to eql 'whateeeeeever'
|
25
25
|
end
|
26
|
+
|
27
|
+
it 'can convert itself into a hash' do
|
28
|
+
configuration = Configuration.new
|
29
|
+
configuration.knowledgebase_url = 'knowledgebase_url'
|
30
|
+
configuration.api_error_documentation_url = 'api_error_documentation_url'
|
31
|
+
configuration.api_version = 'api_version'
|
32
|
+
|
33
|
+
expect(configuration.to_h).to eql(
|
34
|
+
knowledgebase_url: 'knowledgebase_url',
|
35
|
+
api_error_documentation_url: 'api_error_documentation_url',
|
36
|
+
api_version: 'api_version',)
|
37
|
+
end
|
26
38
|
end
|
27
39
|
end
|
data/spec/lib/human_error/errors/authentication_errors/duplicate_authentication_error_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rspectacular'
|
2
2
|
require 'human_error/errors/authentication_errors/duplicate_authentication_error'
|
3
3
|
|
4
|
-
|
4
|
+
class HumanError
|
5
5
|
module Errors
|
6
6
|
describe DuplicateAuthenticationError do
|
7
7
|
let(:error) { DuplicateAuthenticationError.new(provider: 'flibbity',
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rspectacular'
|
2
|
+
require 'human_error'
|
3
|
+
|
4
|
+
describe HumanError do
|
5
|
+
it 'can create an instance of HumanError' do
|
6
|
+
expect(HumanError.new).to be_a HumanError
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'can configure each instance' do
|
10
|
+
human_error = HumanError.new do |config|
|
11
|
+
config.api_version = 'foo'
|
12
|
+
end
|
13
|
+
|
14
|
+
expect(human_error.configuration.api_version).to eql 'foo'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can lookup errors' do
|
18
|
+
human_error = HumanError.new
|
19
|
+
|
20
|
+
expect(human_error.fetch('RequestError')).to be_a HumanError::Errors::RequestError
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'can lookup errors based on the local configuration' do
|
24
|
+
human_error = HumanError.new do |config|
|
25
|
+
config.api_version = 'foo'
|
26
|
+
end
|
27
|
+
|
28
|
+
fetched_error = human_error.fetch('RequestError')
|
29
|
+
|
30
|
+
expect(fetched_error.api_version).to eql 'foo'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'can override values in the global configuration with values in the local configuration when looking up an error' do
|
34
|
+
HumanError.configure do |config|
|
35
|
+
config.api_version = 'bar'
|
36
|
+
end
|
37
|
+
|
38
|
+
human_error = HumanError.new do |config|
|
39
|
+
config.api_version = 'foo'
|
40
|
+
end
|
41
|
+
|
42
|
+
fetched_error = human_error.fetch('RequestError')
|
43
|
+
|
44
|
+
expect(fetched_error.api_version).to eql 'foo'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'can override values in the local configuration with explicit values passed when looking up an error' do
|
48
|
+
human_error = HumanError.new do |config|
|
49
|
+
config.api_version = 'foo'
|
50
|
+
end
|
51
|
+
|
52
|
+
fetched_error = human_error.fetch('RequestError', api_version: 'bar')
|
53
|
+
|
54
|
+
expect(fetched_error.api_version).to eql 'bar'
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'can raise an error' do
|
58
|
+
human_error = HumanError.new
|
59
|
+
|
60
|
+
expect { human_error.raise('RequestError') }.to raise_error HumanError::Errors::RequestError
|
61
|
+
end
|
62
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: human_error
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jfelchner
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- spec/lib/human_error/errors/crud_errors/resource_not_found_error_spec.rb
|
86
86
|
- spec/lib/human_error/errors/crud_errors/resource_persistence_error_spec.rb
|
87
87
|
- spec/lib/human_error/errors/request_error_spec.rb
|
88
|
+
- spec/lib/human_error_spec.rb
|
88
89
|
homepage: https://github.com/thekompanee/human_error
|
89
90
|
licenses: []
|
90
91
|
metadata: {}
|
@@ -118,4 +119,5 @@ test_files:
|
|
118
119
|
- spec/lib/human_error/errors/crud_errors/resource_not_found_error_spec.rb
|
119
120
|
- spec/lib/human_error/errors/crud_errors/resource_persistence_error_spec.rb
|
120
121
|
- spec/lib/human_error/errors/request_error_spec.rb
|
122
|
+
- spec/lib/human_error_spec.rb
|
121
123
|
has_rdoc:
|