Exception: Locd::RequestError

Inherits:
HandledError show all
Defined in:
lib/locd/errors.rb

Overview

Base class for HandledError that happen during request processing which should result in useful error responses to the user.

Direct Known Subclasses

NotFoundError

Constant Summary collapse

STATUS_CODE =
400
STATUS_MESSAGE =
"Bad Request"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = self.class::STATUS_MESSAGE) ⇒ RequestError

Returns a new instance of RequestError.



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

def initialize text = self.class::STATUS_MESSAGE
  @text = text
  super "#{ self.class.status }\n\n#{ text }"
end

Instance Attribute Details

#textattr_type (readonly)

TODO document text attribute.

Returns:

  • (attr_type)


34
35
36
# File 'lib/locd/errors.rb', line 34

def text
  @text
end

Class Method Details

.statusObject



25
26
27
# File 'lib/locd/errors.rb', line 25

def self.status
  "#{ self::STATUS_CODE } #{ self::STATUS_MESSAGE }"
end

Instance Method Details

#to_http_responseObject



42
43
44
# File 'lib/locd/errors.rb', line 42

def to_http_response
  Locd.http_response_for self.class.status, text
end

#to_proxy_machine_cmdObject



46
47
48
# File 'lib/locd/errors.rb', line 46

def to_proxy_machine_cmd
  { close: to_http_response }
end