standard_exceptions 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.idea/.name +1 -0
- data/.idea/compiler.xml +23 -0
- data/.idea/copyright/profiles_settings.xml +3 -0
- data/.idea/encodings.xml +6 -0
- data/.idea/misc.xml +39 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.idea/workspace.xml +1285 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/Rakefile +1 -0
- data/lib/standard_exceptions/application.rb +16 -0
- data/lib/standard_exceptions/application_methods.rb +15 -0
- data/lib/standard_exceptions/http.rb +55 -0
- data/lib/standard_exceptions/http_methods.rb +26 -0
- data/lib/standard_exceptions/version.rb +3 -0
- data/lib/standard_exceptions.rb +45 -0
- data/standard_exceptions.gemspec +24 -0
- data/standard_exceptions.iml +23 -0
- metadata +100 -0
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at gary@buzzware.com.au. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Gary McGhee
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# StandardExceptions
|
2
|
+
|
3
|
+
This is a library of standard exceptions for any project, and nothing else.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'standard_exceptions'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install standard_exceptions
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Just use these standard exceptions for everything, add your own in the same format, and we can start to handle exceptions sanely and reliably.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/standard_exceptions. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
32
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Application Errors
|
2
|
+
module StandardExceptions::Application
|
3
|
+
|
4
|
+
class Failed < ::StandardExceptions::Http::UnprocessableEntity
|
5
|
+
MESSAGE = 'The requested operation was not successful.'
|
6
|
+
end
|
7
|
+
|
8
|
+
class ValidationFailed < Failed
|
9
|
+
MESSAGE = 'The requested operation was not successful due to validation errors.'
|
10
|
+
attr_writer :errors
|
11
|
+
def errors
|
12
|
+
@errors or inner && inner.respond_to?(:errors) && inner.errors
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module StandardExceptions::ApplicationMethods
|
2
|
+
|
3
|
+
include ::StandardExceptions::Application
|
4
|
+
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def validation_failed!(message=nil)
|
8
|
+
raise ValidationFailed.new(message)
|
9
|
+
end
|
10
|
+
|
11
|
+
def failed!(message=nil)
|
12
|
+
raise Failed.new(message)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# HTTP Status Errors
|
2
|
+
module StandardExceptions::Http
|
3
|
+
|
4
|
+
class BadRequest < StandardExceptions::Exception
|
5
|
+
MESSAGE = 'The request was not processed due to a syntax error.'
|
6
|
+
STATUS = 400
|
7
|
+
end
|
8
|
+
class Unauthorized < StandardExceptions::Exception
|
9
|
+
MESSAGE = 'The request was not processed because it lacked acceptable authentication credentials.'
|
10
|
+
STATUS = 401
|
11
|
+
end
|
12
|
+
#PaymentRequired 402
|
13
|
+
class Forbidden < StandardExceptions::Exception
|
14
|
+
MESSAGE = 'The server understood the request but refuses to authorize it.'
|
15
|
+
STATUS = 403
|
16
|
+
end
|
17
|
+
class NotFound < StandardExceptions::Exception
|
18
|
+
MESSAGE = 'The server did not find the requested resource.'
|
19
|
+
STATUS = 404
|
20
|
+
end
|
21
|
+
# MethodNotAllowed 405
|
22
|
+
# NotAcceptable 406
|
23
|
+
# ProxyAuthenticationRequired 407
|
24
|
+
# RequestTimeout 408
|
25
|
+
# Conflict 409
|
26
|
+
# Gone 410
|
27
|
+
# LengthRequired 411
|
28
|
+
# PreconditionFailed 412
|
29
|
+
# RequestEntityTooLarge 413
|
30
|
+
# RequestURITooLong 414
|
31
|
+
# UnsupportedMediaType 415
|
32
|
+
# RequestedRangeNotSatisfiable 416
|
33
|
+
# ExpectationFailed 417
|
34
|
+
class UnprocessableEntity < StandardExceptions::Exception
|
35
|
+
MESSAGE = 'The server understands the request but was unable to process it.'
|
36
|
+
STATUS = 422
|
37
|
+
end
|
38
|
+
# Locked 423
|
39
|
+
# FailedDependency 424
|
40
|
+
# UpgradeRequired 426
|
41
|
+
class InternalServerError < StandardExceptions::Exception
|
42
|
+
MESSAGE = 'The server encountered an unexpected condition that prevented it from fulfilling the request.'
|
43
|
+
STATUS = 500
|
44
|
+
end
|
45
|
+
# class NotImplemented 501
|
46
|
+
# class BadGateway 502
|
47
|
+
# class ServiceUnavailable < Exception
|
48
|
+
# STATUS = 503
|
49
|
+
# end
|
50
|
+
# GatewayTimeout 504
|
51
|
+
# HTTPVersionNotSupported 505
|
52
|
+
# InsufficientStorage 507
|
53
|
+
# NotExtended 510
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module StandardExceptions::HttpMethods
|
2
|
+
|
3
|
+
include ::StandardExceptions::Http
|
4
|
+
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# HTTP Status Errors
|
8
|
+
|
9
|
+
def unauthorized!(message=nil)
|
10
|
+
raise Unauthorized.new(message)
|
11
|
+
end
|
12
|
+
|
13
|
+
def forbidden!(message=nil)
|
14
|
+
raise Forbidden.new(message)
|
15
|
+
end
|
16
|
+
|
17
|
+
def not_found!(message=nil)
|
18
|
+
raise NotFound.new(message)
|
19
|
+
end
|
20
|
+
|
21
|
+
def internal_server_error!(message=nil)
|
22
|
+
raise InternalServerError.new(message)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Application Errors
|
26
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "standard_exceptions/version"
|
2
|
+
|
3
|
+
module StandardExceptions
|
4
|
+
|
5
|
+
# messages are based on http://httpstatuses.com
|
6
|
+
|
7
|
+
class Exception < ::StandardError
|
8
|
+
MESSAGE = 'An error occurred that could not be identified'
|
9
|
+
STATUS = 500
|
10
|
+
|
11
|
+
attr_accessor :status
|
12
|
+
|
13
|
+
# eg. 'Not Found'
|
14
|
+
def self.human_name(e_class=self)
|
15
|
+
i = e_class.name.rindex('::')
|
16
|
+
base_name = e_class.name[(i+2)..-1]
|
17
|
+
base_name.split(/(?=[A-Z])/).join(' ')
|
18
|
+
end
|
19
|
+
|
20
|
+
def human_name
|
21
|
+
self.class.human_name
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_writer :inner
|
25
|
+
def inner
|
26
|
+
@inner || self.cause
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(message=nil,status=nil,inner=nil)
|
30
|
+
super(message || self.class::MESSAGE)
|
31
|
+
@status = (status || self.class::STATUS)
|
32
|
+
@inner = inner
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
require 'standard_exceptions/http'
|
38
|
+
require 'standard_exceptions/application'
|
39
|
+
require 'standard_exceptions/http_methods'
|
40
|
+
require 'standard_exceptions/application_methods'
|
41
|
+
|
42
|
+
module StandardExceptions::Methods
|
43
|
+
include StandardExceptions::HttpMethods
|
44
|
+
include StandardExceptions::ApplicationMethods
|
45
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'standard_exceptions/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "standard_exceptions"
|
8
|
+
spec.version = StandardExceptions::VERSION
|
9
|
+
spec.authors = ["Gary McGhee"]
|
10
|
+
spec.email = ["contact@buzzware.com.au"]
|
11
|
+
|
12
|
+
spec.summary = %q{This is a library of standard exceptions for any project, and nothing else.}
|
13
|
+
spec.description = %q{There is great benefit in adopting a standard library of exceptions. Projects and libraries can all assume the same set of exception classes will be raised and caught using the built in language rescue keyword which filters on class. It becomes especially powerful for building API's, where specific exception classes can be made to return specific HTTP status codes. This libary also provides helper bang-methods eg. unauthorised! for raising these standard kinds of errors}
|
14
|
+
spec.homepage = "http://standardexceptions.org"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="FacetManager">
|
4
|
+
<facet type="gem" name="Ruby Gem">
|
5
|
+
<configuration>
|
6
|
+
<option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
|
7
|
+
<option name="GEM_APP_TEST_PATH" value="" />
|
8
|
+
<option name="GEM_APP_LIB_PATH" value="" />
|
9
|
+
</configuration>
|
10
|
+
</facet>
|
11
|
+
</component>
|
12
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
13
|
+
<exclude-output />
|
14
|
+
<content url="file://$MODULE_DIR$">
|
15
|
+
<excludeFolder url="file://$MODULE_DIR$/.bundle" />
|
16
|
+
<excludeFolder url="file://$MODULE_DIR$/vendor/bundle" />
|
17
|
+
</content>
|
18
|
+
<orderEntry type="jdk" jdkName="RVM: ruby-2.2.5" jdkType="RUBY_SDK" />
|
19
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.12.5, RVM: ruby-2.2.5) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.4.2, RVM: ruby-2.2.5) [gem]" level="application" />
|
22
|
+
</component>
|
23
|
+
</module>
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: standard_exceptions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gary McGhee
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: There is great benefit in adopting a standard library of exceptions.
|
42
|
+
Projects and libraries can all assume the same set of exception classes will be
|
43
|
+
raised and caught using the built in language rescue keyword which filters on class.
|
44
|
+
It becomes especially powerful for building API's, where specific exception classes
|
45
|
+
can be made to return specific HTTP status codes. This libary also provides helper
|
46
|
+
bang-methods eg. unauthorised! for raising these standard kinds of errors
|
47
|
+
email:
|
48
|
+
- contact@buzzware.com.au
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- ".gitignore"
|
54
|
+
- ".idea/.name"
|
55
|
+
- ".idea/compiler.xml"
|
56
|
+
- ".idea/copyright/profiles_settings.xml"
|
57
|
+
- ".idea/encodings.xml"
|
58
|
+
- ".idea/misc.xml"
|
59
|
+
- ".idea/modules.xml"
|
60
|
+
- ".idea/vcs.xml"
|
61
|
+
- ".idea/workspace.xml"
|
62
|
+
- ".travis.yml"
|
63
|
+
- CODE_OF_CONDUCT.md
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/standard_exceptions.rb
|
69
|
+
- lib/standard_exceptions/application.rb
|
70
|
+
- lib/standard_exceptions/application_methods.rb
|
71
|
+
- lib/standard_exceptions/http.rb
|
72
|
+
- lib/standard_exceptions/http_methods.rb
|
73
|
+
- lib/standard_exceptions/version.rb
|
74
|
+
- standard_exceptions.gemspec
|
75
|
+
- standard_exceptions.iml
|
76
|
+
homepage: http://standardexceptions.org
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.8
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: This is a library of standard exceptions for any project, and nothing else.
|
100
|
+
test_files: []
|