lib/hippo/api/request_wrapper.rb in hippo-fw-0.9.1 vs lib/hippo/api/request_wrapper.rb in hippo-fw-0.9.2
- old
+ new
@@ -70,10 +70,17 @@
# Wraps a HTTP request in an optional DB transaction and converts yeilded data to JSON
#
# @param [options] options for additional checks
# @option opts [Boolean] :with_transaction rollback DB transaction if exceptions occur
- def wrap_reply(options = {with_transaction: true})
+ # @option opts [Boolean] :require_tenant return error if tenant is not found
+ def wrap_reply(options = { with_transaction: true, require_tenant: true })
+ if options[:require_tenant] && Hippo::Tenant.current.nil?
+ return json_reply(
+ { success: false, message: "invalid address",
+ errors: { address: 'invalid' } }
+ )
+ end
response = { success: false, message: "No response was generated" }
log_request
if options[:with_transaction]
Hippo::Model.transaction do
response = yield || {success: false}