public
Description: A Ruby web application framework
Homepage: http://www.mackframework.com
Clone URL: git://github.com/markbates/mack.git
Click here to lend your support to: mack and make a donation at www.pledgie.com !
mack / lib / errors / errors.rb
100644 115 lines (102 sloc) 3.934 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
module Mack
  module Errors # :nodoc:
    
    # Raised when there is no session available and one is trying to be accessed.
    class NoSessionError < StandardError
    end
    
    # Raised when someone calls render twice in one action
    #
    # Example:
    # class FooController
    # include Mack::Controller
    # def index
    # render(:text, "Hello World")
    # render(:action, "edit")
    # end
    # end
    class DoubleRender < StandardError
    end # DoubleRender
    
    # Raised when an action returns something other then a string.
    #
    # Example:
    # class FooController
    # include Mack::Controller
    # def index
    # [1,2,3,4]
    # end
    # end
    class InvalidRenderType < StandardError
      # Takes the Class you are trying to render.
      def initialize(klass)
        super("You can not render a #{klass}! It must be a String.")
      end
    end # InvalidRenderType
    
    # Raised when an action tries to render a resource that can't be found.
    #
    # Example:
    # http://www.mackframework.com/my_missing_file.jpg
    class ResourceNotFound < StandardError
      # Takes the resource that can't be found.
      #
      # Example:
      # http://www.mackframework.com/my_missing_file.jpg # => my_missing_file.jpg would be the resource
      def initialize(resource)
        super(resource)
      end
    end # ResourceNotFound
    
    class UnknownController < NameError
    end
    
    # Raised when a route that matches the pattern of the incoming route AND the method of the request can't be found.
    # It's important to note that BOTH the PATTERN and the HTTP METHOD HAVE to match for a route to be found!
    class UndefinedRoute < StandardError
      # Takes a request object.
      def initialize(req)
        super("#{req.path_info}; #{req.request_method}")
      end
    end # UndefinedRoute
    
    # Raised when a layout is specified that doesn't exist.
    class UnknownLayout < StandardError
      # Takes a layout name.
      def initialize(layout)
        super("Could not find layout in: #{File.join(Mack.root, "app", "views", layout.to_s + ".html.erb")}")
      end
    end
    
    # Raised if an unsupported render option is supplied.
    class UnknownRenderOption < StandardError
      # Takes a render option.
      def initialize(opt)
        super("You did not specify a valid render option! '#{opt.inspect}'")
      end
    end
    
    # Raised if a Mack::Controller::Filter returns false.
    class FilterChainHalted < StandardError
      # Takes the name of the filter that returned false.
      def initialize(filter)
        super("The fitler chain was halted because of filter: '#{filter}'")
      end
    end
    
    # Raised if a Mack::Generator::Base required parameter is not supplied.
    class RequiredGeneratorParameterMissing < StandardError
      # Takes the name of the missing parameter.
      def initialize(name)
        super("The required parameter '#{name.to_s.upcase}' is missing for this generator!")
      end
    end
    
    # Potentially raised if a render(:url, "....") is a status other than 200.
    # This is only raised if :raise_exception is passed in as true to the render options.
    class UnsuccessfulRenderUrl < StandardError
      # Takes the uri trying to be rendered the Net::HTTP response object.
      def initialize(uri, response)
        code = response.code if response.respond_to?(:code)
        code = response.status if response.respond_to?(:status)
        super("URI: #{uri}; status: #{code}")
      end
    end
    
    # Raised if an unsupported method, ie post or delete, is used with render url.
    class UnsupportRenderUrlMethodType < StandardError
      # Takes the method tried.
      def initialize(method)
        super("METHOD: #{method.to_s.upcase} is unsupported by render url.")
      end
    end
    
  end # Errors
end # Mack