sinatra-errorcodes 0.1.1 → 0.1.2
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/README.md +18 -5
- data/example/base.rb +3 -2
- data/example/controller.rb +8 -0
- data/lib/sinatra/errorcodes.rb +7 -3
- data/lib/sinatra/errorcodes/version.rb +1 -1
- data/spec/sinatra/errorcodes_spec.rb +12 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 955dff502f8318ac98c598638126e203d488f644
|
4
|
+
data.tar.gz: be2d2ca28b7a20e970849601518a05d334e8dc54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f983f48c729fb9ee14c48be464ae7f0d1922777b99228f29538e90b652f5eefdebbfe87e12e9bc014c11f184c84b4e38a635e700eb47b73cb9f37fb41060786
|
7
|
+
data.tar.gz: 1d1ebf1d01f8dbfbfda412650fb351129920c6bf85124682cdcc6a3310a15c9755f063a688da89fe957cc701c6b93c065f7e4272f2bff4e52b414d1b21fa3e61
|
data/README.md
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
# Sinatra::Errorcodes
|
2
2
|
[](https://badge.fury.io/rb/sinatra-errorcodes)
|
3
3
|
[](https://circleci.com/gh/IzumiSy/sinatra-errorcodes)
|
4
|
+
[](https://github.com/RichardLitt/standard-readme)
|
4
5
|
> Gem of HTTP error status code class pack
|
5
6
|
|
6
|
-
|
7
|
+
=======
|
8
|
+
## Table of Contents
|
9
|
+
- [Installation](#Installation)
|
10
|
+
- [Example](#Example)
|
11
|
+
- [Test](#Test)
|
12
|
+
- [Contribute](#Contribute)
|
13
|
+
- [License](#License)
|
7
14
|
|
15
|
+
## Installation
|
8
16
|
Add this line to your application's Gemfile:
|
9
17
|
|
10
18
|
```ruby
|
@@ -17,22 +25,27 @@ $ gem install sinatra-errorcodes
|
|
17
25
|
```
|
18
26
|
|
19
27
|
## Example
|
20
|
-
|
21
28
|
Install gems
|
22
29
|
```bash
|
23
30
|
$ bundle install
|
24
31
|
```
|
32
|
+
|
25
33
|
and run it
|
26
34
|
```bash
|
27
|
-
$
|
35
|
+
$ cd example
|
36
|
+
$ bundle exec rackup -p 3000
|
28
37
|
```
|
29
38
|
|
30
|
-
##
|
39
|
+
## Test
|
40
|
+
Default task in Rakefile is test
|
41
|
+
```bash
|
42
|
+
$ bundle exec rake
|
43
|
+
```
|
31
44
|
|
45
|
+
## Contribute
|
32
46
|
Bug reports and pull requests are welcome on GitHub at https://github.com/IzumiSy/sinatra-errorcodes. 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.
|
33
47
|
|
34
48
|
|
35
49
|
## License
|
36
|
-
|
37
50
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
38
51
|
|
data/example/base.rb
CHANGED
data/example/controller.rb
CHANGED
@@ -8,4 +8,12 @@ class MainController < BaseController
|
|
8
8
|
get '/error' do
|
9
9
|
raise HTTPError::InternalServerError
|
10
10
|
end
|
11
|
+
|
12
|
+
get '/custom' do
|
13
|
+
raise HTTPError::InternalServerError, "Custom error message"
|
14
|
+
end
|
15
|
+
|
16
|
+
get '/general_error' do
|
17
|
+
undefined_method
|
18
|
+
end
|
11
19
|
end
|
data/lib/sinatra/errorcodes.rb
CHANGED
@@ -3,14 +3,18 @@ require 'sinatra/errorcodes/version'
|
|
3
3
|
|
4
4
|
require_relative '../4xx_errors.rb'
|
5
5
|
require_relative '../5xx_errors.rb'
|
6
|
+
require_relative '../error_base.rb'
|
6
7
|
|
7
8
|
module Sinatra
|
8
9
|
include HTTPError
|
9
10
|
|
10
11
|
module Errorcodes
|
11
|
-
def
|
12
|
-
|
13
|
-
|
12
|
+
def handle_errorcode(e)
|
13
|
+
if e.is_a? ErrorBase
|
14
|
+
halt e.code, e.message
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
18
|
+
|
19
|
+
helpers Errorcodes
|
16
20
|
end
|
@@ -26,4 +26,16 @@ describe Sinatra::Errorcodes do
|
|
26
26
|
expect(last_response.status).to be 400
|
27
27
|
expect(last_response.body).to eq 'Bad Request'
|
28
28
|
end
|
29
|
+
|
30
|
+
it 'returns status 500 with a custom error message' do
|
31
|
+
get '/custom'
|
32
|
+
expect(last_response.status).to be 500
|
33
|
+
expect(last_response.body).to eq 'Custom error message'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns status 500 without a message of HTTPError::InternalServerError' do
|
37
|
+
get '/general_error'
|
38
|
+
expect(last_response.status).to be 500
|
39
|
+
expect(last_response.body).not_to eq 'Internal Server Error'
|
40
|
+
end
|
29
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-errorcodes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IzumiSy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -145,9 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
requirements: []
|
147
147
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.4.5.1
|
149
149
|
signing_key:
|
150
150
|
specification_version: 4
|
151
151
|
summary: '"Sinatra Extension of HTTP error status code pack"'
|
152
152
|
test_files: []
|
153
|
-
has_rdoc:
|