def extract_exception(payload)
      return {} unless payload[:exception]

      exception, message = payload[:exception]
      status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception)
      error_source = $!.backtrace.find { |line| line.match(/\A#{Rails.root}/) }

      result = { status: status }
      result[:error_class] = exception
      result[:error_message] = message
      result[:error_source] = error_source.gsub(/\A#{Dir.pwd}/, '') if error_source
      result[:error_backtrace] = $!.backtrace
      if $!.respond_to?(:cause) && $!.cause
        result[:error_cause] = [$!.cause.class.to_s, $!.cause.message].concat($!.cause.backtrace)
      end
      result
    end
def extract_exception(payload)
      return {} unless payload[:exception]

      exception, message = payload[:exception]
      status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception)
      error_source = $!.backtrace.find { |line| line.match(/\A#{Rails.root}/) }

      result = { status: status }
      result[:error_class] = exception
      result[:error_message] = message
      result[:error_source] = error_source.gsub(/\A#{Dir.pwd}/, '') if error_source
      result[:error_backtrace] = $!.backtrace
      if $!.respond_to?(:cause) && $!.cause
        result[:error_cause] = [$!.cause.class.to_s, $!.cause.message].concat($!.cause.backtrace)
      end
      result
    end
Monkey patching to enable exception logging