human_error 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/human_error/configuration.rb +15 -0
- data/lib/human_error/error.rb +28 -0
- data/lib/human_error/error_code_directory.rb +18 -0
- data/lib/human_error/errors/authentication_error.rb +6 -0
- data/lib/human_error/errors/authentication_errors/invalid_token_error.rb +38 -0
- data/lib/human_error/errors/authentication_errors/invalid_username_or_password_error.rb +38 -0
- data/lib/human_error/errors/crud_error.rb +17 -0
- data/lib/human_error/errors/crud_errors/resource_not_found_error.rb +30 -0
- data/lib/human_error/errors/crud_errors/resource_persistence_error.rb +43 -0
- data/lib/human_error/errors/request_error.rb +57 -0
- data/lib/human_error/utilities/string.rb +15 -0
- data/lib/human_error/version.rb +1 -1
- data/lib/human_error.rb +1 -0
- data/spec/lib/human_error/configuration_spec.rb +27 -0
- data/spec/lib/human_error/errors/authentication_errors/invalid_token_error_spec.rb +34 -0
- data/spec/lib/human_error/errors/authentication_errors/invalid_username_or_password_error_spec.rb +36 -0
- data/spec/lib/human_error/errors/crud_errors/resource_not_found_error_spec.rb +43 -0
- data/spec/lib/human_error/errors/crud_errors/resource_persistence_error_spec.rb +44 -0
- data/spec/lib/human_error/errors/request_error_spec.rb +95 -0
- metadata +40 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2554d092cad72ca391ae12a0d685e65c7cd5f87
|
4
|
+
data.tar.gz: 86be8d5d478e44f36bc91d4553da0c36cef75052
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0260892f92309a5efe0b665fe615b685eb25dac08623eea49dbffd62bb47fdca762c567f7b6234eceac9268d8ac9a2869bfe27c2789ab287ee85726e3b88f489
|
7
|
+
data.tar.gz: d44beaf3bd2c32dd1fa6c3f7d18eb111af1f0f0beb95dd1b69cd51de3bd0965601d1a90bf80c7a6b4f2bfef151aafd72f8e6f6f2911daf84e77428e3b631a9f4
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# HumanError
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/thekompanee/human_error.png?branch=master)](http://travis-ci.org/thekompanee/human_error) [![Code Climate](https://codeclimate.com/github/thekompanee/human_error.png)](https://codeclimate.com/github/thekompanee/human_error) [![Code Climate](https://codeclimate.com/github/thekompanee/human_error/coverage.png)](https://codeclimate.com/github/thekompanee/human_error)
|
4
|
+
|
3
5
|
TODO: Write a gem description
|
4
6
|
|
5
7
|
## Installation
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module HumanError
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :api_version,
|
4
|
+
:api_error_documentation_url,
|
5
|
+
:knowledgebase_url
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configure
|
9
|
+
yield configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configuration
|
13
|
+
@configuration ||= Configuration.new
|
14
|
+
end
|
15
|
+
end
|
data/lib/human_error/error.rb
CHANGED
@@ -1,9 +1,37 @@
|
|
1
|
+
require 'human_error/configuration'
|
2
|
+
require 'human_error/error_code_directory'
|
3
|
+
|
1
4
|
module HumanError
|
2
5
|
module Error
|
6
|
+
attr_accessor :api_version,
|
7
|
+
:api_error_documentation_url,
|
8
|
+
:knowledgebase_url,
|
9
|
+
:code
|
10
|
+
|
11
|
+
def initialize(**args)
|
12
|
+
self.api_version = configuration.api_version
|
13
|
+
self.api_error_documentation_url = configuration.api_error_documentation_url
|
14
|
+
self.knowledgebase_url = configuration.knowledgebase_url
|
15
|
+
|
16
|
+
args.each do |variable, value|
|
17
|
+
self.send("#{variable}=", value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def code
|
22
|
+
@code || ErrorCodeDirectory.lookup(self.class.name)
|
23
|
+
end
|
24
|
+
|
3
25
|
def wrap(other)
|
4
26
|
wrapped_error = new "#{other.class.name}: #{other.message}"
|
5
27
|
wrapped_error.set_backtrace other.backtrace
|
6
28
|
wrapped_error
|
7
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def configuration
|
34
|
+
HumanError.configuration
|
35
|
+
end
|
8
36
|
end
|
9
37
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module HumanError
|
2
|
+
class ErrorCodeDirectory
|
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' => 1003,
|
12
|
+
'HumanError::Errors::InvalidUsernameOrPasswordError' => 1004,
|
13
|
+
'HumanError::Errors::ResourceNotFoundError' => 1005,
|
14
|
+
'HumanError::Errors::ResourcePersistenceError' => 1006,
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'human_error/errors/request_error'
|
2
|
+
require 'human_error/errors/authentication_error'
|
3
|
+
|
4
|
+
module HumanError
|
5
|
+
module Errors
|
6
|
+
class InvalidTokenError < RequestError
|
7
|
+
include AuthenticationError
|
8
|
+
|
9
|
+
attr_accessor :authentication_token
|
10
|
+
|
11
|
+
def initialize(authentication_token: nil, **args)
|
12
|
+
self.authentication_token = authentication_token
|
13
|
+
|
14
|
+
super **args
|
15
|
+
end
|
16
|
+
|
17
|
+
def http_status
|
18
|
+
401
|
19
|
+
end
|
20
|
+
|
21
|
+
def knowledgebase_article_id
|
22
|
+
'1234567890'
|
23
|
+
end
|
24
|
+
|
25
|
+
def developer_message
|
26
|
+
'The token you attempted to use for this request is invalid for this resource. Please double-check and try again.'
|
27
|
+
end
|
28
|
+
|
29
|
+
def developer_details
|
30
|
+
{ token: '[FILTERED]' }
|
31
|
+
end
|
32
|
+
|
33
|
+
def friendly_message
|
34
|
+
'Sorry! You are not authorized to view this.'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'human_error/errors/request_error'
|
2
|
+
require 'human_error/errors/authentication_error'
|
3
|
+
|
4
|
+
module HumanError
|
5
|
+
module Errors
|
6
|
+
class InvalidUsernameOrPasswordError < RequestError
|
7
|
+
include AuthenticationError
|
8
|
+
|
9
|
+
attr_accessor :username
|
10
|
+
|
11
|
+
def initialize(username: nil, **args)
|
12
|
+
self.username = username
|
13
|
+
|
14
|
+
super **args
|
15
|
+
end
|
16
|
+
|
17
|
+
def http_status
|
18
|
+
401
|
19
|
+
end
|
20
|
+
|
21
|
+
def knowledgebase_article_id
|
22
|
+
'1234567890'
|
23
|
+
end
|
24
|
+
|
25
|
+
def developer_message
|
26
|
+
'Either the username or password passed in or this request is invalid. Please double-check and try again.'
|
27
|
+
end
|
28
|
+
|
29
|
+
def developer_details
|
30
|
+
{ :username => username, :password => '[FILTERED]' }
|
31
|
+
end
|
32
|
+
|
33
|
+
def friendly_message
|
34
|
+
'Either your email or password is incorrect. Please double-check and try again.'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module HumanError
|
2
|
+
module Errors
|
3
|
+
module CrudError
|
4
|
+
attr_accessor :resource_name,
|
5
|
+
:action,
|
6
|
+
:resource_id
|
7
|
+
|
8
|
+
def initialize(resource_name: nil, action: nil, resource_id: nil, **args)
|
9
|
+
self.resource_name = resource_name
|
10
|
+
self.action = action
|
11
|
+
self.resource_id = resource_id
|
12
|
+
|
13
|
+
super **args
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'human_error/errors/crud_error'
|
2
|
+
require 'human_error/errors/request_error'
|
3
|
+
|
4
|
+
module HumanError
|
5
|
+
module Errors
|
6
|
+
class ResourceNotFoundError < RequestError
|
7
|
+
include CrudError
|
8
|
+
|
9
|
+
def http_status
|
10
|
+
404
|
11
|
+
end
|
12
|
+
|
13
|
+
def knowledgebase_article_id
|
14
|
+
'1234567890'
|
15
|
+
end
|
16
|
+
|
17
|
+
def developer_message
|
18
|
+
"The #{resource_name} you attempted to #{action} for this request is either not authorized for the authenticated user or does not exist."
|
19
|
+
end
|
20
|
+
|
21
|
+
def developer_details
|
22
|
+
{ "#{resource_name}_id" => resource_id }
|
23
|
+
end
|
24
|
+
|
25
|
+
def friendly_message
|
26
|
+
"Sorry! The #{resource_name} you tried to #{action} does not exist."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'human_error/errors/crud_error'
|
2
|
+
require 'human_error/errors/request_error'
|
3
|
+
|
4
|
+
module HumanError
|
5
|
+
module Errors
|
6
|
+
class ResourcePersistenceError < RequestError
|
7
|
+
include CrudError
|
8
|
+
|
9
|
+
attr_accessor :errors,
|
10
|
+
:attributes
|
11
|
+
|
12
|
+
def initialize(errors: nil, attributes: nil, **args)
|
13
|
+
self.errors = errors
|
14
|
+
self.attributes = attributes
|
15
|
+
|
16
|
+
super **args
|
17
|
+
end
|
18
|
+
|
19
|
+
def http_status
|
20
|
+
422
|
21
|
+
end
|
22
|
+
|
23
|
+
def knowledgebase_article_id
|
24
|
+
'1234567890'
|
25
|
+
end
|
26
|
+
|
27
|
+
def developer_message
|
28
|
+
"One or more of the attributes on the #{resource_name} you attempted to #{action} is invalid."
|
29
|
+
end
|
30
|
+
|
31
|
+
def developer_details
|
32
|
+
{
|
33
|
+
'errors' => errors,
|
34
|
+
'attributes' => attributes,
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def friendly_message
|
39
|
+
"Sorry! We had a problem when tried to #{action} that #{resource_name}."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'human_error/error'
|
2
|
+
require 'human_error/utilities/string'
|
3
|
+
|
4
|
+
module HumanError
|
5
|
+
module Errors
|
6
|
+
class RequestError < RuntimeError
|
7
|
+
include HumanError::Error
|
8
|
+
|
9
|
+
attr_accessor :http_status,
|
10
|
+
:developer_message,
|
11
|
+
:developer_details,
|
12
|
+
:friendly_message,
|
13
|
+
:knowledgebase_article_id
|
14
|
+
|
15
|
+
def as_json(options = {})
|
16
|
+
{
|
17
|
+
error: {
|
18
|
+
status: http_status,
|
19
|
+
code: code,
|
20
|
+
developer_documentation_uri: developer_documentation_uri,
|
21
|
+
customer_support_uri: customer_support_uri,
|
22
|
+
developer_message_key: developer_message_key,
|
23
|
+
developer_message: developer_message,
|
24
|
+
developer_details: developer_details,
|
25
|
+
friendly_message_key: friendly_message_key,
|
26
|
+
friendly_message: friendly_message,
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def developer_documentation_uri
|
34
|
+
"#{api_error_documentation_url}/#{code}?version=#{api_version}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def customer_support_uri
|
38
|
+
"#{knowledgebase_url}/#{knowledgebase_article_id}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def base_message_key
|
42
|
+
HumanError::Utilities::String.
|
43
|
+
underscore(self.class.name).
|
44
|
+
gsub(%r{\A[^/]+/}, '').
|
45
|
+
gsub(%r{[_/]}, '.')
|
46
|
+
end
|
47
|
+
|
48
|
+
def developer_message_key
|
49
|
+
"#{base_message_key}.developer"
|
50
|
+
end
|
51
|
+
|
52
|
+
def friendly_message_key
|
53
|
+
"#{base_message_key}.friendly"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module HumanError
|
2
|
+
module Utilities
|
3
|
+
class String
|
4
|
+
def self.underscore(other)
|
5
|
+
word = other.to_s.gsub('::', '/')
|
6
|
+
word.gsub!(/(?:([A-Za-z\d])|^)(?=\b|[^a-z])/) { "#{$1}#{$1 && ''}" }
|
7
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
8
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
9
|
+
word.tr!("-", "_")
|
10
|
+
word.downcase!
|
11
|
+
word
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/human_error/version.rb
CHANGED
data/lib/human_error.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rspectacular'
|
2
|
+
require 'human_error/configuration'
|
3
|
+
|
4
|
+
module HumanError
|
5
|
+
describe Configuration do
|
6
|
+
it 'can set the API version' do
|
7
|
+
configuration = Configuration.new
|
8
|
+
configuration.api_version = 'whateeeeeever'
|
9
|
+
|
10
|
+
expect(configuration.api_version).to eql 'whateeeeeever'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can set the API error documentation URL' do
|
14
|
+
configuration = Configuration.new
|
15
|
+
configuration.api_error_documentation_url = 'whateeeeeever'
|
16
|
+
|
17
|
+
expect(configuration.api_error_documentation_url).to eql 'whateeeeeever'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'can set the knowledgebase URL' do
|
21
|
+
configuration = Configuration.new
|
22
|
+
configuration.knowledgebase_url = 'whateeeeeever'
|
23
|
+
|
24
|
+
expect(configuration.knowledgebase_url).to eql 'whateeeeeever'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rspectacular'
|
2
|
+
require 'human_error/errors/authentication_errors/invalid_token_error'
|
3
|
+
|
4
|
+
module HumanError
|
5
|
+
module Errors
|
6
|
+
describe InvalidTokenError do
|
7
|
+
let(:error) { InvalidTokenError.new }
|
8
|
+
|
9
|
+
it 'has a status of 401' do
|
10
|
+
expect(error.http_status).to eql 401
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has a code of 1003' do
|
14
|
+
expect(error.code).to eql 1003
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has a knowledgebase article ID of 1234567890' do
|
18
|
+
expect(error.knowledgebase_article_id).to eql '1234567890'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'can output the developer message' do
|
22
|
+
expect(error.developer_message).to eql 'The token you attempted to use for this request is invalid for this resource. Please double-check and try again.'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'can output the developer details' do
|
26
|
+
expect(error.developer_details).to eql(token: '[FILTERED]')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'can output the friendly message' do
|
30
|
+
expect(error.friendly_message).to eql 'Sorry! You are not authorized to view this.'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/lib/human_error/errors/authentication_errors/invalid_username_or_password_error_spec.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rspectacular'
|
2
|
+
require 'human_error/errors/authentication_errors/invalid_username_or_password_error'
|
3
|
+
|
4
|
+
module HumanError
|
5
|
+
module Errors
|
6
|
+
describe InvalidUsernameOrPasswordError do
|
7
|
+
let(:error) { InvalidUsernameOrPasswordError.new }
|
8
|
+
|
9
|
+
it 'has a status of 401' do
|
10
|
+
expect(error.http_status).to eql 401
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has a code of 1004' do
|
14
|
+
expect(error.code).to eql 1004
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has a knowledgebase article ID of 1234567890' do
|
18
|
+
expect(error.knowledgebase_article_id).to eql '1234567890'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'can output the developer message' do
|
22
|
+
expect(error.developer_message).to eql 'Either the username or password passed in or this request is invalid. Please double-check and try again.'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'can output the developer details' do
|
26
|
+
error = InvalidUsernameOrPasswordError.new username: 'neo'
|
27
|
+
|
28
|
+
expect(error.developer_details).to eql(:username => 'neo', :password => '[FILTERED]')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'can output the friendly message' do
|
32
|
+
expect(error.friendly_message).to eql 'Either your email or password is incorrect. Please double-check and try again.'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rspectacular'
|
2
|
+
require 'human_error/errors/crud_errors/resource_not_found_error'
|
3
|
+
|
4
|
+
module HumanError
|
5
|
+
module Errors
|
6
|
+
describe ResourceNotFoundError do
|
7
|
+
let(:error) { ResourceNotFoundError.new }
|
8
|
+
|
9
|
+
it 'has a status of 404' do
|
10
|
+
expect(error.http_status).to eql 404
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has a code of 1005' do
|
14
|
+
expect(error.code).to eql 1005
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has a knowledgebase article ID of 1234567890' do
|
18
|
+
expect(error.knowledgebase_article_id).to eql '1234567890'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'includes the resource name and action in the developer message' do
|
22
|
+
error = ResourceNotFoundError.new resource_name: 'black leather trenchcoat',
|
23
|
+
action: 'bullet time'
|
24
|
+
|
25
|
+
expect(error.developer_message).to eql "The black leather trenchcoat you attempted to bullet time for this request is either not authorized for the authenticated user or does not exist."
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'includes the resource name and action in the developer details' do
|
29
|
+
error = ResourceNotFoundError.new resource_name: 'black leather trenchcoat',
|
30
|
+
resource_id: 123
|
31
|
+
|
32
|
+
expect(error.developer_details).to eql("black leather trenchcoat_id" => 123)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'includes the resource name and action in the friendly message' do
|
36
|
+
error = ResourceNotFoundError.new resource_name: 'black leather trenchcoat',
|
37
|
+
action: 'bullet time'
|
38
|
+
|
39
|
+
expect(error.friendly_message).to eql "Sorry! The black leather trenchcoat you tried to bullet time does not exist."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rspectacular'
|
2
|
+
require 'human_error/errors/crud_errors/resource_persistence_error'
|
3
|
+
|
4
|
+
module HumanError
|
5
|
+
module Errors
|
6
|
+
describe ResourcePersistenceError do
|
7
|
+
let(:error) { ResourcePersistenceError.new }
|
8
|
+
|
9
|
+
it 'has a status of 422' do
|
10
|
+
expect(error.http_status).to eql 422
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has a code of 1006' do
|
14
|
+
expect(error.code).to eql 1006
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has a knowledgebase article ID of 1234567890' do
|
18
|
+
expect(error.knowledgebase_article_id).to eql '1234567890'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'includes the resource name and action in the developer message' do
|
22
|
+
error = ResourcePersistenceError.new resource_name: 'black leather trenchcoat',
|
23
|
+
action: 'bullet time'
|
24
|
+
|
25
|
+
expect(error.developer_message).to eql "One or more of the attributes on the black leather trenchcoat you attempted to bullet time is invalid."
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'includes the resource name and action in the developer details' do
|
29
|
+
error = ResourcePersistenceError.new errors: 'lots of errors',
|
30
|
+
attributes: 'what is the matrix'
|
31
|
+
|
32
|
+
expect(error.developer_details).to eql('errors' => 'lots of errors',
|
33
|
+
'attributes' => 'what is the matrix')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'includes the resource name and action in the friendly message' do
|
37
|
+
error = ResourcePersistenceError.new resource_name: 'black leather trenchcoat',
|
38
|
+
action: 'bullet time'
|
39
|
+
|
40
|
+
expect(error.friendly_message).to eql "Sorry! We had a problem when tried to bullet time that black leather trenchcoat."
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'rspectacular'
|
2
|
+
require 'human_error/errors/request_error'
|
3
|
+
|
4
|
+
module HumanError
|
5
|
+
module Errors
|
6
|
+
describe RequestError do
|
7
|
+
it 'can generate error data' do
|
8
|
+
request_error = RequestError.new(http_status: 'flibbity',
|
9
|
+
code: 'jibbit',
|
10
|
+
developer_message: 'I cannot receive any satisfaction',
|
11
|
+
developer_details: 'But perhaps if I attempt it one more time, I can',
|
12
|
+
friendly_message: 'receive what I need',
|
13
|
+
knowledgebase_article_id: '87654321',
|
14
|
+
api_version: 'janky',
|
15
|
+
api_error_documentation_url: 'asimof',
|
16
|
+
knowledgebase_url: 'jinkies')
|
17
|
+
|
18
|
+
expect(request_error.as_json).to eql({
|
19
|
+
error: {
|
20
|
+
status: 'flibbity',
|
21
|
+
code: 'jibbit',
|
22
|
+
developer_documentation_uri: 'asimof/jibbit?version=janky',
|
23
|
+
customer_support_uri: 'jinkies/87654321',
|
24
|
+
developer_message_key: 'errors.request.error.developer',
|
25
|
+
developer_message: 'I cannot receive any satisfaction',
|
26
|
+
developer_details: 'But perhaps if I attempt it one more time, I can',
|
27
|
+
friendly_message_key: 'errors.request.error.friendly',
|
28
|
+
friendly_message: 'receive what I need',
|
29
|
+
}
|
30
|
+
})
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'can extract configuration from the global config if it is not passed in' do
|
34
|
+
HumanError.configure do |config|
|
35
|
+
config.api_version = 'janky'
|
36
|
+
config.api_error_documentation_url = 'asimof'
|
37
|
+
config.knowledgebase_url = 'jinkies'
|
38
|
+
end
|
39
|
+
|
40
|
+
request_error = RequestError.new(http_status: 'flibbity',
|
41
|
+
code: 'jibbit',
|
42
|
+
developer_message: 'I cannot receive any satisfaction',
|
43
|
+
developer_details: 'But perhaps if I attempt it one more time, I can',
|
44
|
+
friendly_message: 'receive what I need',
|
45
|
+
knowledgebase_article_id: '87654321')
|
46
|
+
|
47
|
+
expect(request_error.as_json).to eql({
|
48
|
+
error: {
|
49
|
+
status: 'flibbity',
|
50
|
+
code: 'jibbit',
|
51
|
+
developer_documentation_uri: 'asimof/jibbit?version=janky',
|
52
|
+
customer_support_uri: 'jinkies/87654321',
|
53
|
+
developer_message_key: 'errors.request.error.developer',
|
54
|
+
developer_message: 'I cannot receive any satisfaction',
|
55
|
+
developer_details: 'But perhaps if I attempt it one more time, I can',
|
56
|
+
friendly_message_key: 'errors.request.error.friendly',
|
57
|
+
friendly_message: 'receive what I need',
|
58
|
+
}
|
59
|
+
})
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'can override the global config if it is set, but an explicit value is passed in' do
|
63
|
+
HumanError.configure do |config|
|
64
|
+
config.api_version = 'janky'
|
65
|
+
config.api_error_documentation_url = 'asimof'
|
66
|
+
config.knowledgebase_url = 'jinkies'
|
67
|
+
end
|
68
|
+
|
69
|
+
request_error = RequestError.new(http_status: 'flibbity',
|
70
|
+
code: 'jibbit',
|
71
|
+
developer_message: 'I cannot receive any satisfaction',
|
72
|
+
developer_details: 'But perhaps if I attempt it one more time, I can',
|
73
|
+
friendly_message: 'receive what I need',
|
74
|
+
knowledgebase_article_id: '87654321',
|
75
|
+
api_version: 'hanky',
|
76
|
+
api_error_documentation_url: 'hasimof',
|
77
|
+
knowledgebase_url: 'hinkies')
|
78
|
+
|
79
|
+
expect(request_error.as_json).to eql({
|
80
|
+
error: {
|
81
|
+
status: 'flibbity',
|
82
|
+
code: 'jibbit',
|
83
|
+
developer_documentation_uri: 'hasimof/jibbit?version=hanky',
|
84
|
+
customer_support_uri: 'hinkies/87654321',
|
85
|
+
developer_message_key: 'errors.request.error.developer',
|
86
|
+
developer_message: 'I cannot receive any satisfaction',
|
87
|
+
developer_details: 'But perhaps if I attempt it one more time, I can',
|
88
|
+
friendly_message_key: 'errors.request.error.friendly',
|
89
|
+
friendly_message: 'receive what I need',
|
90
|
+
}
|
91
|
+
})
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: human_error
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jfelchner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -30,14 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.22'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.22'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: codeclimate-test-reporter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.3.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.3.0
|
41
55
|
description: ''
|
42
56
|
email: accounts+git@thekompanee.com
|
43
57
|
executables: []
|
@@ -48,9 +62,25 @@ files:
|
|
48
62
|
- README.md
|
49
63
|
- Rakefile
|
50
64
|
- lib/human_error.rb
|
65
|
+
- lib/human_error/configuration.rb
|
51
66
|
- lib/human_error/error.rb
|
67
|
+
- lib/human_error/error_code_directory.rb
|
68
|
+
- lib/human_error/errors/authentication_error.rb
|
69
|
+
- lib/human_error/errors/authentication_errors/invalid_token_error.rb
|
70
|
+
- lib/human_error/errors/authentication_errors/invalid_username_or_password_error.rb
|
71
|
+
- lib/human_error/errors/crud_error.rb
|
72
|
+
- lib/human_error/errors/crud_errors/resource_not_found_error.rb
|
73
|
+
- lib/human_error/errors/crud_errors/resource_persistence_error.rb
|
74
|
+
- lib/human_error/errors/request_error.rb
|
75
|
+
- lib/human_error/utilities/string.rb
|
52
76
|
- lib/human_error/version.rb
|
77
|
+
- spec/lib/human_error/configuration_spec.rb
|
53
78
|
- spec/lib/human_error/error_spec.rb
|
79
|
+
- spec/lib/human_error/errors/authentication_errors/invalid_token_error_spec.rb
|
80
|
+
- spec/lib/human_error/errors/authentication_errors/invalid_username_or_password_error_spec.rb
|
81
|
+
- spec/lib/human_error/errors/crud_errors/resource_not_found_error_spec.rb
|
82
|
+
- spec/lib/human_error/errors/crud_errors/resource_persistence_error_spec.rb
|
83
|
+
- spec/lib/human_error/errors/request_error_spec.rb
|
54
84
|
homepage: https://github.com/thekompanee/human_error
|
55
85
|
licenses: []
|
56
86
|
metadata: {}
|
@@ -76,5 +106,11 @@ signing_key:
|
|
76
106
|
specification_version: 4
|
77
107
|
summary: Common Error Extensions and Helpers
|
78
108
|
test_files:
|
109
|
+
- spec/lib/human_error/configuration_spec.rb
|
79
110
|
- spec/lib/human_error/error_spec.rb
|
111
|
+
- spec/lib/human_error/errors/authentication_errors/invalid_token_error_spec.rb
|
112
|
+
- spec/lib/human_error/errors/authentication_errors/invalid_username_or_password_error_spec.rb
|
113
|
+
- spec/lib/human_error/errors/crud_errors/resource_not_found_error_spec.rb
|
114
|
+
- spec/lib/human_error/errors/crud_errors/resource_persistence_error_spec.rb
|
115
|
+
- spec/lib/human_error/errors/request_error_spec.rb
|
80
116
|
has_rdoc:
|