sinatra-errorcodes 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73fd3195d815e79e8b533b13e88192ed9bc80a45
4
- data.tar.gz: 80aa76c52909abb1c72704426c750962bbff5704
3
+ metadata.gz: 955dff502f8318ac98c598638126e203d488f644
4
+ data.tar.gz: be2d2ca28b7a20e970849601518a05d334e8dc54
5
5
  SHA512:
6
- metadata.gz: aefe182ef6d17d69ed764fb8fef79923d3645b965d9318660ba58616ece701fcbf5bf5330005ca3367f04238461de2cf7ce65964b33498e55d3d83b07748d2a5
7
- data.tar.gz: 775606957fbe5f45ed8033aaa5866c6247bf73fb7f40eb81757188cc71956e5a1df7d76f6899492dba10de8e0bc24ba20cd1aa77a699d1cf43a38d524b7b4418
6
+ metadata.gz: 3f983f48c729fb9ee14c48be464ae7f0d1922777b99228f29538e90b652f5eefdebbfe87e12e9bc014c11f184c84b4e38a635e700eb47b73cb9f37fb41060786
7
+ data.tar.gz: 1d1ebf1d01f8dbfbfda412650fb351129920c6bf85124682cdcc6a3310a15c9755f063a688da89fe957cc701c6b93c065f7e4272f2bff4e52b414d1b21fa3e61
data/README.md CHANGED
@@ -1,10 +1,18 @@
1
1
  # Sinatra::Errorcodes
2
2
  [![Gem Version](https://badge.fury.io/rb/sinatra-errorcodes.svg)](https://badge.fury.io/rb/sinatra-errorcodes)
3
3
  [![CircleCI](https://circleci.com/gh/IzumiSy/sinatra-errorcodes.svg?style=shield)](https://circleci.com/gh/IzumiSy/sinatra-errorcodes)
4
+ [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
4
5
  > Gem of HTTP error status code class pack
5
6
 
6
- ## Installation
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
- $ rackup -p 3000
35
+ $ cd example
36
+ $ bundle exec rackup -p 3000
28
37
  ```
29
38
 
30
- ## Contributing
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
 
@@ -1,11 +1,12 @@
1
1
  class BaseController < Sinatra::Base
2
2
  configure do
3
+ helpers Sinatra::Errorcodes
4
+
3
5
  set :raise_errors, false
4
6
  set :show_exceptions, false
5
7
  end
6
8
 
7
9
  error do |e|
8
- body e.message
9
- status e.code
10
+ handle_errorcode(e)
10
11
  end
11
12
  end
@@ -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
@@ -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 self.registered(app)
12
- # TODO: Here overrides error do ... end section
13
- # in order to set up exception handlings.
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
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Errorcodes
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  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.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-06-29 00:00:00.000000000 Z
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.6.4
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: