human_error 1.0.0 → 1.1.0
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/lib/human_error/error.rb +15 -0
- data/lib/human_error/error_code_directory.rb +1 -0
- data/lib/human_error/errors/authentication_errors/invalid_token_error.rb +0 -4
- data/lib/human_error/errors/authentication_errors/invalid_username_or_password_error.rb +0 -4
- data/lib/human_error/errors/crud_errors/resource_not_found_error.rb +0 -4
- data/lib/human_error/errors/request_error.rb +1 -6
- data/lib/human_error/errors.rb +7 -0
- data/lib/human_error/knowledgebase_id_directory.rb +19 -0
- data/lib/human_error/version.rb +1 -1
- 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: c2a02b1eac36cbd434a65f917be7e4a2fcd46b15
|
4
|
+
data.tar.gz: a644e1253d0fd7707c8d2a96b9bc6309ac5f18b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7db25d17b98cbcb92a16e267fb847a6708d3140ab682148c8c27037884feb5fdcf1c95ad432481f7ee01cfa86b1d5d73e02ac5fd41f0eb3423849b1650dd1032
|
7
|
+
data.tar.gz: 42450a0be1844e0483c3157829ec0275ffcf7b650cbe52cb6f31e22501b6f99ba33d89b26a58b51ac15d89083fb31474ad849cdbaf3211514e7bc70ee0aec9eb
|
data/lib/human_error/error.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
+
require 'json'
|
1
2
|
require 'human_error/configuration'
|
2
3
|
require 'human_error/error_code_directory'
|
4
|
+
require 'human_error/knowledgebase_id_directory'
|
3
5
|
|
4
6
|
module HumanError
|
5
7
|
module Error
|
6
8
|
attr_accessor :api_version,
|
7
9
|
:api_error_documentation_url,
|
8
10
|
:knowledgebase_url,
|
11
|
+
:knowledgebase_article_id,
|
9
12
|
:code
|
10
13
|
|
11
14
|
def initialize(**args)
|
@@ -22,6 +25,18 @@ module Error
|
|
22
25
|
@code || ErrorCodeDirectory.lookup(self.class.name)
|
23
26
|
end
|
24
27
|
|
28
|
+
def knowledgebase_article_id
|
29
|
+
@knowledgebase_article_id || KnowledgebaseIdDirectory.lookup(self.class.name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def customer_support_uri
|
33
|
+
"#{knowledgebase_url}/#{knowledgebase_article_id}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_json
|
37
|
+
JSON.dump(as_json)
|
38
|
+
end
|
39
|
+
|
25
40
|
def wrap(other)
|
26
41
|
wrapped_error = new "#{other.class.name}: #{other.message}"
|
27
42
|
wrapped_error.set_backtrace other.backtrace
|
@@ -12,6 +12,7 @@ class ErrorCodeDirectory
|
|
12
12
|
'HumanError::Errors::InvalidUsernameOrPasswordError' => 1004,
|
13
13
|
'HumanError::Errors::ResourceNotFoundError' => 1005,
|
14
14
|
'HumanError::Errors::ResourcePersistenceError' => 1006,
|
15
|
+
'Apill::Errors::InvalidApiRequestError' => 1007,
|
15
16
|
}
|
16
17
|
end
|
17
18
|
end
|
@@ -18,10 +18,6 @@ class InvalidTokenError < RequestError
|
|
18
18
|
401
|
19
19
|
end
|
20
20
|
|
21
|
-
def knowledgebase_article_id
|
22
|
-
'1234567890'
|
23
|
-
end
|
24
|
-
|
25
21
|
def developer_message
|
26
22
|
'The token you attempted to use for this request is invalid for this resource. Please double-check and try again.'
|
27
23
|
end
|
@@ -18,10 +18,6 @@ class InvalidUsernameOrPasswordError < RequestError
|
|
18
18
|
401
|
19
19
|
end
|
20
20
|
|
21
|
-
def knowledgebase_article_id
|
22
|
-
'1234567890'
|
23
|
-
end
|
24
|
-
|
25
21
|
def developer_message
|
26
22
|
'Either the username or password passed in or this request is invalid. Please double-check and try again.'
|
27
23
|
end
|
@@ -10,10 +10,6 @@ class ResourceNotFoundError < RequestError
|
|
10
10
|
404
|
11
11
|
end
|
12
12
|
|
13
|
-
def knowledgebase_article_id
|
14
|
-
'1234567890'
|
15
|
-
end
|
16
|
-
|
17
13
|
def developer_message
|
18
14
|
"The #{resource_name} you attempted to #{action} for this request is either not authorized for the authenticated user or does not exist."
|
19
15
|
end
|
@@ -9,8 +9,7 @@ class RequestError < RuntimeError
|
|
9
9
|
attr_accessor :http_status,
|
10
10
|
:developer_message,
|
11
11
|
:developer_details,
|
12
|
-
:friendly_message
|
13
|
-
:knowledgebase_article_id
|
12
|
+
:friendly_message
|
14
13
|
|
15
14
|
def as_json(options = {})
|
16
15
|
{
|
@@ -34,10 +33,6 @@ class RequestError < RuntimeError
|
|
34
33
|
"#{api_error_documentation_url}/#{code}?version=#{api_version}"
|
35
34
|
end
|
36
35
|
|
37
|
-
def customer_support_uri
|
38
|
-
"#{knowledgebase_url}/#{knowledgebase_article_id}"
|
39
|
-
end
|
40
|
-
|
41
36
|
def base_message_key
|
42
37
|
HumanError::Utilities::String.
|
43
38
|
underscore(self.class.name).
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'human_error/errors/request_error'
|
2
|
+
require 'human_error/errors/authentication_error'
|
3
|
+
require 'human_error/errors/authentication_errors/invalid_token_error'
|
4
|
+
require 'human_error/errors/authentication_errors/invalid_username_or_password_error'
|
5
|
+
require 'human_error/errors/crud_error'
|
6
|
+
require 'human_error/errors/crud_errors/resource_not_found_error'
|
7
|
+
require 'human_error/errors/crud_errors/resource_persistence_error'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module HumanError
|
2
|
+
class KnowledgebaseIdDirectory
|
3
|
+
def self.lookup(error_class)
|
4
|
+
directory[error_class]
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def self.directory
|
10
|
+
{
|
11
|
+
'HumanError::Errors::InvalidTokenError' => '1234567890',
|
12
|
+
'HumanError::Errors::InvalidUsernameOrPasswordError' => '1234567890',
|
13
|
+
'HumanError::Errors::ResourceNotFoundError' => '1234567890',
|
14
|
+
'HumanError::Errors::ResourcePersistenceError' => '1234567890',
|
15
|
+
'Apill::Errors::InvalidApiRequestError' => '1234567890',
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/human_error/version.rb
CHANGED
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jfelchner
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/human_error/configuration.rb
|
66
66
|
- lib/human_error/error.rb
|
67
67
|
- lib/human_error/error_code_directory.rb
|
68
|
+
- lib/human_error/errors.rb
|
68
69
|
- lib/human_error/errors/authentication_error.rb
|
69
70
|
- lib/human_error/errors/authentication_errors/invalid_token_error.rb
|
70
71
|
- lib/human_error/errors/authentication_errors/invalid_username_or_password_error.rb
|
@@ -72,6 +73,7 @@ files:
|
|
72
73
|
- lib/human_error/errors/crud_errors/resource_not_found_error.rb
|
73
74
|
- lib/human_error/errors/crud_errors/resource_persistence_error.rb
|
74
75
|
- lib/human_error/errors/request_error.rb
|
76
|
+
- lib/human_error/knowledgebase_id_directory.rb
|
75
77
|
- lib/human_error/utilities/string.rb
|
76
78
|
- lib/human_error/version.rb
|
77
79
|
- spec/lib/human_error/configuration_spec.rb
|