lib/petit/app.rb
# Builds an error message JSON object
#
# @param [Hash] opts the options to create the JSON object
# @option opts [Integer] :error_code the http error code that will accompany the message
# @option opts [String] :message (optional) the error message
# @option opts [String] :pointer (optional) A JSON Pointer (RRC6901) to the associated entity
#   in the request document
# @option opts [String] :parameter (optional) a string indicating which URI query parameter
#   caused the error.
# @return [String] a JSON string representing the error message
Builds an error message JSON object
Builds an error message JSON object
def build_json_error(opts = {})
      json_body = { errors: [{ status: opts[:error_code] }] }
      json_body[:errors][0].store('message', opts[:message]) if opts[:message]
      if opts[:pointer]
        json_body[:errors][0].store(
          'source',
          build_json_error_source(
            opts[:pointer],
            opts[:parameter]
          )
        )
      end
      json_body.to_json
    end
def build_json_error ( opts = { } ) json_body = { errors : [ { status : opts [ :error_code ] } ] } json_body [ :errors ] [ 0 ] . store ( 'message' , opts [ :message ] ) if opts [ :message ] if opts [ :pointer ] json_body [ :errors ] [ 0 ] . store ( 'source' , build_json_error_source ( opts [ :pointer ] , opts [ :parameter ] ) ) end json_body . to_json end
Builds an error message JSON object
Builds an error message JSON object
a JSON string representing the error message
a JSON string representing the error message
String
opts
:parameter (optional) a string indicating which URI query parameter caused the error.
: parameter ( optional ) a string indicating which URI query parameter caused the error .
<not_specific>
opts the options to create the JSON object
opts the options to create the JSON object