Class: Doze::Responder::Error
- Inherits:
-
Doze::Responder
- Object
- Doze::Responder
- Doze::Responder::Error
- Defined in:
- lib/doze/responder/error.rb
Constant Summary
Constants included from Utils
Instance Attribute Summary
Attributes inherited from Doze::Responder
Instance Method Summary collapse
-
#initialize(app, request, error) ⇒ Error
constructor
A new instance of Error.
-
#response ⇒ Object
We use a resource class to represent for errors to enable content type negotiation for them.
Methods inherited from Doze::Responder
#auth_failed_response, #call, #error_response, #error_response_from_error, #raise_error, #recognized_method
Methods included from Utils
#escape, #quote, #request_base_uri, #unescape
Constructor Details
#initialize(app, request, error) ⇒ Error
Returns a new instance of Error.
3 4 5 6 |
# File 'lib/doze/responder/error.rb', line 3 def initialize(app, request, error) super(app, request) @error = error end |
Instance Method Details
#response ⇒ Object
We use a resource class to represent for errors to enable content type negotiation for them. The class used is configurable but defaults to Doze::Resource::Error
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/doze/responder/error.rb', line 10 def response response = Doze::Response.new if @app.config[:error_resource_class] extras = {:error => @error} if @app.config[:expose_exception_details] && @error.http_status >= 500 extras[:backtrace] = @error.backtrace end resource = @app.config[:error_resource_class].new(@error.http_status, @error., extras) # we can't have it going STATUS_NOT_ACCEPTABLE in the middle of trying to return an error resource, so :ignore_unacceptable_accepts responder = Doze::Responder::Resource.new(@app, @request, resource, :ignore_unacceptable_accepts => true) entity = responder.get_preferred_representation(response) response.entity = entity else response.headers['Content-Type'] = 'text/plain' response.body = @error. end response.head_only = true if @request.head? response.status = @error.http_status response.headers.merge!(@error.headers) if @error.headers response end |