lib/petit/app.rb
# Returns a HTTP error code and formatted error message
#
# @param [Hash] opts the options to created the error
# @option opts [Integer] :error_code (Defaults to 500) the error code to be returned
# @option opts [String] :message (optional) the error message to accompany the error code
# @option opts [String] :pointer (optional) a JSON Pointer (RFC6901) to the associated entity
#  in the request document
# @option opts [String] :parameter (optional) a string indicating which URI query parameter
#  caused the error.
Returns a HTTP error code and formatted error message
Returns a HTTP error code and formatted error message
def return_error(opts = {})
      opts[:error_code] = opts[:error_code] || 500
      opts[:message] =  opts[:message] || 'An Internal Error Occurred'
      if request.accept?('application/json') || request.accept?('application/vnd.api+json')
        response.headers['Content-Type'] = 'application/vnd.api+json'
        halt opts[:error_code], build_json_error(opts)
      else
        halt opts[:error_code], opts[:message]
      end
    end
def return_error ( opts = { } ) opts [ :error_code ] = opts [ :error_code ] || 500 opts [ :message ] = opts [ :message ] || 'An Internal Error Occurred' if request . accept? ( 'application/json' ) || request . accept? ( 'application/vnd.api+json' ) response . headers [ 'Content-Type' ] = 'application/vnd.api+json' halt opts [ :error_code ] , build_json_error ( opts ) else halt opts [ :error_code ] , opts [ :message ] end end
Returns a HTTP error code and formatted error message
Returns a HTTP error code and formatted error message
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 created the error
opts the options to created the error