dzl 1.0.0.rc7 → 1.0.0.rc8
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.
- data/config.ru +8 -8
- data/lib/dzl/dsl_proxies/router.rb +6 -0
- data/lib/dzl/dsl_subjects/router.rb +2 -1
- data/lib/dzl/examples/fun_with_handlers.rb +18 -0
- data/lib/dzl/rack_interface.rb +22 -8
- data/lib/dzl/version.rb +1 -1
- data/spec/fun_with_handlers_spec.rb +13 -1
- metadata +6 -6
data/config.ru
CHANGED
@@ -15,10 +15,10 @@ end
|
|
15
15
|
# run Dzl::Examples::Trey
|
16
16
|
# end
|
17
17
|
|
18
|
-
require 'dzl/examples/fun_with_params'
|
19
|
-
map '/' do
|
20
|
-
|
21
|
-
end
|
18
|
+
# require 'dzl/examples/fun_with_params'
|
19
|
+
# map '/' do
|
20
|
+
# run Dzl::Examples::FunWithParams
|
21
|
+
# end
|
22
22
|
|
23
23
|
# require 'dzl/examples/fun_with_requests'
|
24
24
|
# map '/' do
|
@@ -30,10 +30,10 @@ end
|
|
30
30
|
# run Dzl::Examples::RouteProfile
|
31
31
|
# end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
require 'dzl/examples/fun_with_handlers'
|
34
|
+
map '/' do
|
35
|
+
run Dzl::Examples::FunWithHandlers
|
36
|
+
end
|
37
37
|
|
38
38
|
# require 'dzl/examples/fun_with_hooks'
|
39
39
|
# map '/' do
|
@@ -46,6 +46,12 @@ class Dzl::DSLProxies::Router < Dzl::DSLProxy
|
|
46
46
|
@subject.call_with_subject(Proc.new, @subject.defaults_dslsub)
|
47
47
|
end
|
48
48
|
|
49
|
+
def error_hook(&block)
|
50
|
+
raise ArgumentError unless block_given?
|
51
|
+
|
52
|
+
@subject.error_hooks << block
|
53
|
+
end
|
54
|
+
|
49
55
|
REQUEST_METHODS.each do |m|
|
50
56
|
define_method(m) do |route, *request_methods, &block|
|
51
57
|
request_methods << m
|
@@ -3,7 +3,7 @@ require 'dzl/dsl_subjects/defaults'
|
|
3
3
|
|
4
4
|
class Dzl::DSLSubjects::Router < Dzl::DSLSubject
|
5
5
|
include Dzl::RouterDoc
|
6
|
-
attr_reader :pblocks, :defaults_dslsub, :defaults, :app
|
6
|
+
attr_reader :pblocks, :defaults_dslsub, :defaults, :app, :error_hooks
|
7
7
|
|
8
8
|
def initialize(app)
|
9
9
|
@pblocks = {}
|
@@ -16,6 +16,7 @@ class Dzl::DSLSubjects::Router < Dzl::DSLSubject
|
|
16
16
|
@defaults_dslsub = Dzl::DSLSubjects::Defaults.new(self)
|
17
17
|
@dsl_proxy = Dzl::DSLProxies::Router.new(self)
|
18
18
|
@app = app
|
19
|
+
@error_hooks = []
|
19
20
|
end
|
20
21
|
|
21
22
|
def call_with_subject(proc, subject)
|
@@ -5,6 +5,18 @@ class Dzl::Examples::FunWithHandlers < Dzl::Examples::Base
|
|
5
5
|
content_type 'application/json'
|
6
6
|
end
|
7
7
|
|
8
|
+
error_hook do |e|
|
9
|
+
Object.first_error_hook
|
10
|
+
end
|
11
|
+
|
12
|
+
error_hook do |e|
|
13
|
+
Object.second_error_hook
|
14
|
+
|
15
|
+
if e.to_s.match('explode')
|
16
|
+
raise 'explode'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
8
20
|
endpoint '/say_bar' do
|
9
21
|
optional :foo, :bar, :baz, :bam
|
10
22
|
|
@@ -31,6 +43,12 @@ class Dzl::Examples::FunWithHandlers < Dzl::Examples::Base
|
|
31
43
|
end
|
32
44
|
end
|
33
45
|
|
46
|
+
get '/explode' do
|
47
|
+
handle do
|
48
|
+
raise 'explode'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
34
52
|
get '/validation_error' do
|
35
53
|
handle do
|
36
54
|
raise Dzl::ValidationError.new(
|
data/lib/dzl/rack_interface.rb
CHANGED
@@ -10,23 +10,30 @@ module Dzl::RackInterface
|
|
10
10
|
request = nil
|
11
11
|
start_time = Time.now
|
12
12
|
start_profile if PROFILE_REQUESTS
|
13
|
-
response = begin
|
13
|
+
response, error = begin
|
14
14
|
request = Dzl::Request.new(env)
|
15
|
-
__router.handle_request(request)
|
15
|
+
[__router.handle_request(request), nil]
|
16
16
|
rescue Dzl::RespondWithHTTPBasicChallenge
|
17
|
-
respond_with_http_basic_challenge
|
17
|
+
[respond_with_http_basic_challenge, nil]
|
18
18
|
rescue Dzl::Error => e
|
19
|
-
respond_with_dzl_error_handler(e)
|
19
|
+
[respond_with_dzl_error_handler(e), nil]
|
20
20
|
rescue StandardError => e
|
21
|
-
respond_with_standard_error_handler(e)
|
21
|
+
[respond_with_standard_error_handler(e), e]
|
22
22
|
end
|
23
23
|
|
24
24
|
if response[0] < 100
|
25
|
-
|
25
|
+
error = Dzl::Error.new('Application did not respond')
|
26
|
+
response = respond_with_standard_error_handler(error)
|
27
|
+
end
|
28
|
+
|
29
|
+
if error.present?
|
30
|
+
__router.error_hooks.each do |hook|
|
31
|
+
hook.call(error) rescue nil
|
32
|
+
end
|
26
33
|
end
|
27
34
|
|
28
35
|
stop_profiling_and_print if PROFILE_REQUESTS
|
29
|
-
log_request(request, response, (Time.now - start_time)) unless request.silent?
|
36
|
+
log_request(request, response, (Time.now - start_time), error) unless request.silent?
|
30
37
|
|
31
38
|
if Dzl.production? || Dzl.staging?
|
32
39
|
(response[0] < 500) ? response : [response[0], [], [response[0].to_s]]
|
@@ -88,10 +95,17 @@ module Dzl::RackInterface
|
|
88
95
|
)
|
89
96
|
end
|
90
97
|
|
91
|
-
def log_request(request, response, seconds)
|
98
|
+
def log_request(request, response, seconds, error)
|
92
99
|
logger.info "#{request.request_method} #{request.path}"
|
93
100
|
logger.info "PARAMS: #{request.params}"
|
94
101
|
logger.debug "BODY: #{request.body}" unless request.body.blank?
|
95
102
|
logger.info "#{response[0]} in #{seconds * 1000}ms"
|
103
|
+
|
104
|
+
if error.present?
|
105
|
+
logger.info error.inspect
|
106
|
+
error.backtrace.each do |line|
|
107
|
+
logger.info " #{line}"
|
108
|
+
end
|
109
|
+
end
|
96
110
|
end
|
97
111
|
end
|
data/lib/dzl/version.rb
CHANGED
@@ -29,12 +29,24 @@ describe 'handlers' do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
it '
|
32
|
+
it 'calls error hooks on errors' do
|
33
|
+
Object.should_receive(:first_error_hook)
|
34
|
+
Object.should_receive(:second_error_hook)
|
35
|
+
|
33
36
|
get '/raise' do |response|
|
34
37
|
response.status.should == 500
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
41
|
+
it 'exceptions raised in error hooks are squashed, sorry' do
|
42
|
+
Object.should_receive(:first_error_hook)
|
43
|
+
Object.should_receive(:second_error_hook)
|
44
|
+
|
45
|
+
get '/explode' do |response|
|
46
|
+
response.status.should == 500
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
38
50
|
it 'are good places to raise Dzl::ValidationError' do
|
39
51
|
get '/validation_error' do |response|
|
40
52
|
response.status.should == 404
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dzl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc8
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-05-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rack
|
17
|
-
requirement: &
|
17
|
+
requirement: &70294010134960 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 1.4.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70294010134960
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activesupport
|
28
|
-
requirement: &
|
28
|
+
requirement: &70294010134460 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: 3.2.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70294010134460
|
37
37
|
description: Small, fast racktivesupport web framework with handy DSL and explicit
|
38
38
|
parameter validation.
|
39
39
|
email:
|