schneiderlein 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +34 -0
- data/Rakefile +30 -0
- data/app/assets/stylesheets/schneiderlein/application.css +15 -0
- data/app/controllers/schneiderlein/application_controller.rb +4 -0
- data/app/helpers/schneiderlein/application_helper.rb +4 -0
- data/app/views/layouts/schneiderlein/application.html.erb +14 -0
- data/config/routes.rb +2 -0
- data/lib/schneiderlein.rb +6 -0
- data/lib/schneiderlein/catch.rb +21 -0
- data/lib/schneiderlein/engine.rb +11 -0
- data/lib/schneiderlein/fly_catcher.rb +24 -0
- data/lib/schneiderlein/version.rb +3 -0
- data/lib/tasks/schneiderlein_tasks.rake +4 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 20c6f68046204b95dee35b2fabf1414dd7941318
|
4
|
+
data.tar.gz: c9944fd48128f918e30fab816297c6c2af5ac13b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 944d61cbeb56ff25b778e02a255e154061b7b5cd191569acf36d28af55dd0f17ebe648c3901f69eabd3d6edab3a1b39d0a984dac669baa68d56fd370e2659b51
|
7
|
+
data.tar.gz: 66a3f38f45bd26a88b81469f23d47cc458890ae72b6a6abf588b133ab5bb6a8eff8ec03caf39fda4331dfa5c33a19359b089b1cf0438a0f4036baa0228892c22
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Schneiderlein [![Build Status](https://travis-ci.org/Absolventa/schneiderlein.svg?branch=master)](https://travis-ci.org/Absolventa/schneiderlein)
|
2
|
+
|
3
|
+
**Schneiderlein** is a Rack middleware to catch parse errors coming from [ActionDispatch::ParamsParser](https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/params_parser.rb). Malformed XML presents a 500 Internal Server Error to your API consumer. It's hardly meaningful, should instead be in the 4xx range and most importantly: it's not helping.
|
4
|
+
|
5
|
+
Since the error appears early in the middleware stack, there is no way to use `rescue_from` on controller-level in a Rails app. **Schneiderlein** blanks the defective POST data from the request environment, saves the `ParseError`'s message and passes the modified Rack env along the middleware stack.
|
6
|
+
|
7
|
+
The original error message is saved as `rack.schneiderlein.parse_errors` in the request environment. `Schneiderlein::Catch` aims to provide a convenient accessor. See the usage example below.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Add the gem to your Rails app's Gemfile. In your API controller, you may want to add something like this:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
class Api::BaseController < ApplicationController
|
15
|
+
before_action :handle_parse_errors
|
16
|
+
|
17
|
+
respond_to :json, :xml
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def handle_parse_errors
|
22
|
+
schneiderlein = Schneiderlein::Catch.new(request)
|
23
|
+
respond_with schneiderlein.errors, status: 422 if schneiderlein.errors.any?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
## Naming
|
29
|
+
The name **Schneiderlein** is derived from the fairytale »Das Tapfere Schneiderlein« (»The Valiant Little Tailor«) by the Grimm Brothers. The Valiant Little Tailor catches flies, **Schneiderlein** catches errors. Funny, eh?
|
30
|
+
|
31
|
+
## Changelog
|
32
|
+
|
33
|
+
### 1.0.0
|
34
|
+
* Initial release
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Schneiderlein'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
|
25
|
+
require 'rspec/core'
|
26
|
+
require 'rspec/core/rake_task'
|
27
|
+
|
28
|
+
RSpec::Core::RakeTask.new(:spec)
|
29
|
+
|
30
|
+
task default: :spec
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Schneiderlein</title>
|
5
|
+
<%= stylesheet_link_tag "schneiderlein/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "schneiderlein/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Schneiderlein
|
2
|
+
class Catch
|
3
|
+
delegate :any?, :empty?, to: :errors
|
4
|
+
|
5
|
+
attr_reader :request
|
6
|
+
|
7
|
+
def initialize(request)
|
8
|
+
@request = request
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_a
|
12
|
+
request.env.fetch('rack.schneiderlein.parse_errors', [])
|
13
|
+
end
|
14
|
+
|
15
|
+
alias errors to_a
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
to_a.map(&:message).join ' '
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Schneiderlein
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace Schneiderlein
|
4
|
+
|
5
|
+
initializer 'schneiderlein.middleware' do |app|
|
6
|
+
app.config.middleware.insert_before \
|
7
|
+
'ActionDispatch::ParamsParser', 'Schneiderlein::FlyCatcher'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Schneiderlein
|
2
|
+
class FlyCatcher < Struct.new(:app)
|
3
|
+
def call(env)
|
4
|
+
begin
|
5
|
+
app.call(env)
|
6
|
+
rescue ActionDispatch::ParamsParser::ParseError => e
|
7
|
+
env['rack.schneiderlein.parse_errors'] ||= []
|
8
|
+
env['rack.schneiderlein.parse_errors'] << e
|
9
|
+
app.call(remove_errors_from(env))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def remove_errors_from(env)
|
16
|
+
env['rack.input'] = StringIO.new
|
17
|
+
env['rack.errors'] = StringIO.new
|
18
|
+
env['RAW_POST_DATA'] = ''
|
19
|
+
env['CONTENT_LENGTH'] = '0'
|
20
|
+
env
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: schneiderlein
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carsten Zimmermann
|
8
|
+
- Robin Neumann
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 4.0.0
|
21
|
+
- - <
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '5.0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 4.0.0
|
31
|
+
- - <
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: appraisal
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: sqlite3
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec-rails
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
type: :development
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
description: Rescues from ActionDispatch::ParamsParser and continues in middleware
|
77
|
+
stack
|
78
|
+
email:
|
79
|
+
- cz@aegisnet.de
|
80
|
+
- robin.neumann@absolventa.de
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- MIT-LICENSE
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- app/assets/stylesheets/schneiderlein/application.css
|
89
|
+
- app/controllers/schneiderlein/application_controller.rb
|
90
|
+
- app/helpers/schneiderlein/application_helper.rb
|
91
|
+
- app/views/layouts/schneiderlein/application.html.erb
|
92
|
+
- config/routes.rb
|
93
|
+
- lib/schneiderlein.rb
|
94
|
+
- lib/schneiderlein/catch.rb
|
95
|
+
- lib/schneiderlein/engine.rb
|
96
|
+
- lib/schneiderlein/fly_catcher.rb
|
97
|
+
- lib/schneiderlein/version.rb
|
98
|
+
- lib/tasks/schneiderlein_tasks.rake
|
99
|
+
homepage: https://github.com/Absolventa/schneiderlein
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.2.2
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Rack middleware that rescues from ActionDispatch::ParamsParser
|
123
|
+
test_files: []
|