Sha256: fd10e2f49bb6a499dcc704582176f3403e9afa99db98aa6e8c23cc46fec8cf8a

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

class Card
  class Format
    module Error
      def rescue_view e, view
        method = loud_error? ? :loud_error : :quiet_error
        send method, e, view
      end

      def error_cardname _exception
        if card&.name.present?
          safe_name
        else
          I18n.t :no_cardname, scope: %i[lib card format error]
        end
      end

      def loud_error?
        focal? || Card.config.raise_all_rendering_errors
      end

      def loud_error e, view
        card.errors.add "#{view} view", rendering_error(e, view) if card.errors.empty?
        raise e
      end

      def quiet_error e, view
        # TODO: unify with Card::Error#report
        Rails.logger.info "#{e.message}\n" + (e.backtrace * "\n")
        rendering_error e, view
      end

      def rendering_error exception, view
        if exception.is_a? Card::Error::UserError
          exception.message
        else
          tr :error_rendering, scope: %i[lib card format error],
                               cardname: error_cardname(exception), view: view
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
card-1.97.0.1 lib/card/format/error.rb