module Strelka::ResponseHelpers
A collection of functions for generating responses.
Public Instance Methods
finish_with( http_status, message=nil, headers={} )
click to toggle source
Abort the current execution and return a response with the specified http_status code immediately. The specified message
will be logged, and will be included in any message that is returned as part of the response. The headers
hash will be used to set response headers. As a shortcut, you can call finish_with
again with the Hash that it builds to re-throw it.
# File lib/strelka/mixins.rb, line 368 def finish_with( http_status, message=nil, headers={} ) status_info = nil if http_status.is_a?( Hash ) && http_status.key?(:status) self.log.debug "Re-finishing with a status_info struct: %p." % [ http_status ] status_info = http_status else message ||= HTTP::STATUS_NAME[ http_status ] status_info = { status: http_status, message: message, headers: headers, backtrace: caller(1), } end # Log using the instance logger if possible, else use the global one logmsg = "Finishing with status %d: %s" % [ status_info[:status], status_info[:message] ] if status_info[:status] > 399 self.log.info( logmsg ) else self.log.error( logmsg ) end throw :finish, status_info end