Exception: Apique::MalformedParameters

Inherits:
Exception
  • Object
show all
Defined in:
lib/apique/listable.rb

Overview

Exception will raise if a request query would contain an incorrect of malformed parameter. This will provide the front-end with a description of the correct API usage.

Instance Method Summary collapse

Constructor Details

#initialize(request, param, params_usage, *args) ⇒ MalformedParameters

Returns a new instance of MalformedParameters.



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/apique/listable.rb', line 36

def initialize(request, param, params_usage, *args)
  message = "Bad request query: malformed parameter #{param}"
  usage = "GET #{request.fullpath[/[^?]+/]}?#{params_usage.keys*'&'}"
  
  @json = {message: message, usage: usage, params: params_usage.values}
  
  message = [
    message, "Usage: #{usage}",
    *params_usage.values.flat_map {|v| [v[:desc], "Example: #{v[:example]}"]}
  ]*"\n"
  
  super(message, *args)
end

Instance Method Details

#as_jsonObject



50
51
52
# File 'lib/apique/listable.rb', line 50

def as_json(*)
  @json
end