Exception: RequestError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/frecon/request_error.rb

Overview

Public: A class representing errors that emanate from request handling.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, message = nil, context = nil) ⇒ RequestError

Public: Initialize a RequestError.

code - An Integer representing the HTTP status code. message - A String representing the error message. context - An Object containing any necessary debugging values.



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
# File 'lib/frecon/request_error.rb', line 24

def initialize(code, message = nil, context = nil)
	@code = code
	@message = message
	@context = context

	# When @message is a String or an Array,
	# the return_value is set to a Sinatra-compliant
	# Array with @code being the first element and the
	# response body being the stringification of the
	# JSON stringification of @context and @message.
	#
	# If @message is a String, it is first put into an
	# array.
	#
	# If @message is neither a String nor an Array,
	# @return_value becomes simply @code.
	@return_value =
		case @message
		when String
			[@code, JSON.generate({ context: @context, errors: [ @message ] })]
		when Array
			[@code, JSON.generate({ context: @context, errors: @message })]
		else
			@code
		end
end

Instance Attribute Details

#return_valueObject (readonly)

Public: The Array or Integer representing what can be returned from the request handler.



17
18
19
# File 'lib/frecon/request_error.rb', line 17

def return_value
  @return_value
end