Exception: Tap::Server::ServerError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/tap/server/server_error.rb

Overview

A special type of error used for specifiying controller errors.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body = "500 Server Error", status = 500, headers = {'Content-Type' => 'text/plain'}) ⇒ ServerError

Returns a new instance of ServerError.



22
23
24
25
26
27
# File 'lib/tap/server/server_error.rb', line 22

def initialize(body="500 Server Error", status=500, headers={'Content-Type' => 'text/plain'})
  @body = body
  @status = status
  @headers = headers
  super(body)
end

Instance Attribute Details

#bodyObject (readonly)

The error response body



20
21
22
# File 'lib/tap/server/server_error.rb', line 20

def body
  @body
end

#headersObject (readonly)

Headers for the error response



17
18
19
# File 'lib/tap/server/server_error.rb', line 17

def headers
  @headers
end

#statusObject (readonly)

The error status



14
15
16
# File 'lib/tap/server/server_error.rb', line 14

def status
  @status
end

Class Method Details

.response(err) ⇒ Object

A helper to format a non-ServerError into a ServerError response.



8
9
10
# File 'lib/tap/server/server_error.rb', line 8

def response(err)
  new("500 #{err.class}: #{err.message}\n#{err.backtrace.join("\n")}").response
end

Instance Method Details

#responseObject

Formats self as a rack response array (ie [status, headers, body]).



30
31
32
# File 'lib/tap/server/server_error.rb', line 30

def response
  [status, headers, [body]]
end