Exception: Sidewalk::HttpError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/sidewalk/errors.rb

Overview

Base class for HTTP errors.

This is raised by controllers.

Instance Method Summary collapse

Constructor Details

#initialize(status, description) ⇒ HttpError

Initialize an Error exception.

If the parameters are nil, you will need to override #status and #description for this class to work as expected.

Parameters:

  • status (Fixnum, nil)

    is the numeric status code

  • description (String, nil)

    is a short description like ‘Not Found’



14
15
16
# File 'lib/sidewalk/errors.rb', line 14

def initialize status, description
  @status, @description = status, description
end

Instance Method Details

#description(request) ⇒ String

The description to return in response to the request.

It takes a request to allow different responses to be given to, for example, HTTP/1.0 clients vs HTTP/1.1 clients.

Parameters:

  • request (Request)

    is an object representing the current HTTP request

Returns:

  • (String)

    a text description of the code, like ‘Not Found’



38
39
40
# File 'lib/sidewalk/errors.rb', line 38

def description request
  @description
end

#status(request) ⇒ Fixnum

The status code to return in response to the request.

It takes a request to allow different responses to be given to, for example, HTTP/1.0 clients vs HTTP/1.1 clients.

Parameters:

  • request (Request)

    is an object representing the current HTTP request

Returns:

  • (Fixnum)

    a numeric HTTP status code.



26
27
28
# File 'lib/sidewalk/errors.rb', line 26

def status request
  @status
end