Sha256: 1a965dd4b2bfb92fbba2d59a7101cef26dc6155892699e530c782169f33a9179

Contents?: true

Size: 785 Bytes

Versions: 47

Compression:

Stored size: 785 Bytes

Contents

# frozen_string_literal: true

class ErrorHandlingWithChainsController < ApplicationController

  # Example where the query chain is resolved
  # in the view (during render 'show')
  def fetch_in_view
    @records = Record
      .handle(LHC::Error, ->(error) { handle_error(error) })
      .where(color: 'blue')
    render 'show'
    render_error if @error
  end

  # Example where the query chain is resolved
  # before the view is rendered
  def fetch_in_controller
    @records = Record
      .handle(LHC::Error, ->(error) { handle_error(error) })
      .where(color: 'blue').fetch
    render 'show'
    render_error if @error
  end

  private

  def handle_error(error)
    @error = error
    nil
  end

  def render_error
    self.response_body = nil
    render 'error'
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
lhs-21.2.2 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.2.1 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.2.0 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.1.4 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.1.3 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.1.2 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.1.2.pre.keyfix.2 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.1.2.pre.keyfix.1 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.1.2.pre.fix.pre.cant.pre.add.pre.new.pre.key.pre.during.pre.iteration.1 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.1.1.pre.pre.fix.pre.cant.pre.add.pre.new.pre.key.pre.during.pre.iteration.1 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.1.0 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.0.0 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-20.1.4 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-20.1.3.pre.paginationfix.3 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-20.1.3.pre.paginationfix.2 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-20.1.3.pre.paginationfix.1 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-20.1.2 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-20.1.1 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-20.0.0 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-19.10.0 spec/dummy/app/controllers/error_handling_with_chains_controller.rb