http-errors 0.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +48 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/http_errors.gemspec +29 -0
- data/lib/http_error.rb +14 -0
- data/lib/http_error/bad_request.rb +8 -0
- data/lib/http_error/error.rb +17 -0
- data/lib/http_error/forbidden.rb +9 -0
- data/lib/http_error/internal_server_error.rb +8 -0
- data/lib/http_error/not_implemented.rb +8 -0
- data/lib/http_error/response.rb +20 -0
- data/lib/http_error/teapot.rb +8 -0
- data/lib/http_error/unauthorized.rb +9 -0
- data/lib/http_error/version.rb +3 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1a271c0fe06315eced591d92050aea5e00c78c8d54b15a4dd1716ec99f5ced8e
|
4
|
+
data.tar.gz: 9c4649b2a906dcb41dce8da9f5ee08de560cade21d29a54ef686e8762eb05080
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 769b0fdac3e1f9251e60384dfa59dbd0c18b6ec4d5ad9e697699136903b4d63aa4e9ebde5a75187a6a523e91d938d6935c5f2c8062dae621a1eff4bdd92bd840
|
7
|
+
data.tar.gz: 94eb2f036196a25ff6b8b2cba58a78c4bfe1e7205ef1df494df0f3b52137631420350f0b533580970ee7f11df4c8ca250695589a6b6cd659224b8f167261e161
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
http-errors (0.1.0)
|
5
|
+
activesupport (~> 5.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (5.1.6)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 0.7, < 2)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
tzinfo (~> 1.1)
|
15
|
+
concurrent-ruby (1.0.5)
|
16
|
+
diff-lcs (1.3)
|
17
|
+
i18n (1.0.0)
|
18
|
+
concurrent-ruby (~> 1.0)
|
19
|
+
minitest (5.11.3)
|
20
|
+
rake (10.5.0)
|
21
|
+
rspec (3.7.0)
|
22
|
+
rspec-core (~> 3.7.0)
|
23
|
+
rspec-expectations (~> 3.7.0)
|
24
|
+
rspec-mocks (~> 3.7.0)
|
25
|
+
rspec-core (3.7.1)
|
26
|
+
rspec-support (~> 3.7.0)
|
27
|
+
rspec-expectations (3.7.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.7.0)
|
30
|
+
rspec-mocks (3.7.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.7.0)
|
33
|
+
rspec-support (3.7.1)
|
34
|
+
thread_safe (0.3.6)
|
35
|
+
tzinfo (1.2.5)
|
36
|
+
thread_safe (~> 0.1)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
bundler (~> 1.16)
|
43
|
+
http-errors!
|
44
|
+
rake (~> 10.0)
|
45
|
+
rspec (~> 3.0)
|
46
|
+
|
47
|
+
BUNDLED WITH
|
48
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Emil Kampp
|
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,51 @@
|
|
1
|
+
# HTTP errors
|
2
|
+
|
3
|
+
Simple HTTP errors for your Ruby application. You can see [a complete list of http errors here](https://httpstatuses.com).
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Install it
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'http-errors', require: 'http_error'
|
11
|
+
```
|
12
|
+
|
13
|
+
Then in your application you can raise an HTTP error
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
raise HttpError::Unauthorized
|
17
|
+
```
|
18
|
+
|
19
|
+
You can also set some detail information about the error
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
raise HttpError::Unauthorized, 'Invalid email or password'
|
23
|
+
```
|
24
|
+
|
25
|
+
In your ApplicationController you can then handle the errors like this
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class ApplicationController < ActionController::Base
|
29
|
+
include HttpError::Response
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
Or you can implement your own handler for all `HttpError`s
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
class ApplicationController < ActionController::Base
|
37
|
+
rescue_from HttpError::Error do |error|
|
38
|
+
# Handle the error here
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
Or for a specific, single error
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
class ApplicationController < ActionController::Base
|
47
|
+
rescue_from HttpError::Teapot do |error|
|
48
|
+
render json: { error: 'This is silly' }, status: 418
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "http_errors"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/http_errors.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "http_error/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "http-errors"
|
8
|
+
spec.version = HttpErrors::VERSION
|
9
|
+
spec.authors = ["Emil Kampp"]
|
10
|
+
spec.email = ["emil@kampp.me"]
|
11
|
+
|
12
|
+
spec.summary = 'Easy way to raise HTTP errors from your ruby application'
|
13
|
+
spec.description = 'Easy way to raise HTTP errors from your ruby application'
|
14
|
+
spec.homepage = "https://github.com/YouWeApS/arctic-gems-http_errors"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
|
28
|
+
spec.add_runtime_dependency "activesupport", "~> 5.1"
|
29
|
+
end
|
data/lib/http_error.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Gems
|
2
|
+
require 'active_support/all'
|
3
|
+
|
4
|
+
# Framework
|
5
|
+
require "http_error/version"
|
6
|
+
require "http_error/response"
|
7
|
+
|
8
|
+
# Errors
|
9
|
+
require "http_error/bad_request"
|
10
|
+
require "http_error/forbidden"
|
11
|
+
require "http_error/internal_server_error"
|
12
|
+
require "http_error/not_implemented"
|
13
|
+
require "http_error/teapot"
|
14
|
+
require "http_error/unauthorized"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module HttpError
|
2
|
+
# InternalServerError is used by all other errors to inherit from
|
3
|
+
class Error < StandardError
|
4
|
+
class << self
|
5
|
+
attr_accessor :status
|
6
|
+
attr_accessor :message
|
7
|
+
end
|
8
|
+
|
9
|
+
def status
|
10
|
+
self.class.status
|
11
|
+
end
|
12
|
+
|
13
|
+
def error
|
14
|
+
message || self.class.message
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module HttpError
|
2
|
+
module Response
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
rescue_from HttpError::Error do |error|
|
7
|
+
Rails.logger.debug "Rescuing from #{error.class}. Status: #{error.status}. Message: #{error.message}"
|
8
|
+
|
9
|
+
hash = {
|
10
|
+
error: error.message,
|
11
|
+
}
|
12
|
+
|
13
|
+
render \
|
14
|
+
text: error.message,
|
15
|
+
json: hash,
|
16
|
+
status: error.status
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http-errors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emil Kampp
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-05 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '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: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.1'
|
69
|
+
description: Easy way to raise HTTP errors from your ruby application
|
70
|
+
email:
|
71
|
+
- emil@kampp.me
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- http_errors.gemspec
|
87
|
+
- lib/http_error.rb
|
88
|
+
- lib/http_error/bad_request.rb
|
89
|
+
- lib/http_error/error.rb
|
90
|
+
- lib/http_error/forbidden.rb
|
91
|
+
- lib/http_error/internal_server_error.rb
|
92
|
+
- lib/http_error/not_implemented.rb
|
93
|
+
- lib/http_error/response.rb
|
94
|
+
- lib/http_error/teapot.rb
|
95
|
+
- lib/http_error/unauthorized.rb
|
96
|
+
- lib/http_error/version.rb
|
97
|
+
homepage: https://github.com/YouWeApS/arctic-gems-http_errors
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.7.3
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Easy way to raise HTTP errors from your ruby application
|
121
|
+
test_files: []
|