dzl 1.0.0.rc5 → 1.0.0.rc6

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/lib/dzl/errors.rb CHANGED
@@ -38,3 +38,4 @@ end
38
38
 
39
39
  class Dzl::RetryBlockPlease < Dzl::Error; end
40
40
  class Dzl::Deprecated < Dzl::Error; end
41
+ class Dzl::ValidationError < Dzl::RequestError; end
@@ -30,4 +30,13 @@ class Dzl::Examples::FunWithHandlers < Dzl::Examples::Base
30
30
  raise 'omg'
31
31
  end
32
32
  end
33
+
34
+ get '/validation_error' do
35
+ handle do
36
+ raise Dzl::ValidationError.new(
37
+ any: 'hash',
38
+ i: 'want'
39
+ )
40
+ end
41
+ end
33
42
  end
@@ -62,4 +62,10 @@ class Dzl::Examples::FunWithHooks < Dzl::Examples::Base
62
62
  raise Dzl::BadRequest.new("This isn't quite what I was expecting")
63
63
  end
64
64
  end
65
+
66
+ endpoint '/validation_error' do
67
+ after_validate do
68
+ raise Dzl::ValidationError.new(any: 'hash', i: 'want')
69
+ end
70
+ end
65
71
  end
@@ -63,8 +63,8 @@ module Dzl::RackInterface
63
63
  response = Rack::Response.new
64
64
  response.headers['Content-Type'] = 'application/json'
65
65
 
66
- if e.is_a?(Dzl::RequestError)
67
- response.status = e.status
66
+ if e.is_a?(Dzl::ValidationError)
67
+ response.status = 404
68
68
  response.write(e.to_json)
69
69
  else
70
70
  response.status = e.status
@@ -34,6 +34,14 @@ class Dzl::ResponseContext
34
34
  @response.write(value)
35
35
  end
36
36
 
37
+ @response
38
+ rescue Dzl::ValidationError => e
39
+ @response.status = 404
40
+ @response.write({
41
+ errors: {
42
+ @endpoint.route => e.data
43
+ }
44
+ }.to_json)
37
45
  @response
38
46
  end
39
47
 
data/lib/dzl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dzl
2
- VERSION = "1.0.0.rc5"
2
+ VERSION = "1.0.0.rc6"
3
3
  end
@@ -34,4 +34,14 @@ describe 'handlers' do
34
34
  response.status.should == 500
35
35
  end
36
36
  end
37
+
38
+ it 'are good places to raise Dzl::ValidationError' do
39
+ get '/validation_error' do |response|
40
+ response.status.should == 404
41
+ JSON.parse(response.body)['errors']['/validation_error'].should == {
42
+ 'any' => 'hash',
43
+ 'i' => 'want'
44
+ }
45
+ end
46
+ end
37
47
  end
@@ -57,5 +57,15 @@ describe 'FunWithHooks' do
57
57
  JSON.parse(response.body)['errors'].should == "This isn't quite what I was expecting"
58
58
  end
59
59
  end
60
+
61
+ it 'are good places to raise Dzl::ValidationError' do
62
+ get('/validation_error') do |response|
63
+ response.status.should == 404
64
+ JSON.parse(response.body)['errors']['/validation_error'].should == {
65
+ 'any' => 'hash',
66
+ 'i' => 'want'
67
+ }
68
+ end
69
+ end
60
70
  end
61
71
  end
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.rc5
4
+ version: 1.0.0.rc6
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-04-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
17
- requirement: &70321920004760 !ruby/object:Gem::Requirement
17
+ requirement: &70264021734620 !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: *70321920004760
25
+ version_requirements: *70264021734620
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &70321920003960 !ruby/object:Gem::Requirement
28
+ requirement: &70264021734100 !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: *70321920003960
36
+ version_requirements: *70264021734100
37
37
  description: Small, fast racktivesupport web framework with handy DSL and explicit
38
38
  parameter validation.
39
39
  email: