class RequestError
Public: A class representing errors that emanate from request handling.
Attributes
return_value[R]
Public: The Array or Integer representing what can be returned from the request handler.
Public Class Methods
new(code, message = nil, context = nil)
click to toggle source
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.
# 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