Sha256: 3b6c4f8b18e97d7ce2ce0a51c58108f14c29e774133fa1fed08b59bf770f48a5

Contents?: true

Size: 795 Bytes

Versions: 12

Compression:

Stored size: 795 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 = DummyRecord
      .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 = DummyRecord
      .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

12 entries across 12 versions & 1 rubygems

Version Path
lhs-23.0.2 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-23.0.1 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-23.0.0 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-22.1.1.pre spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-22.1.0 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-22.0.0 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.3.1 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.3.0 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.3.0.pre.autoauth.1 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.2.4 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.2.3 spec/dummy/app/controllers/error_handling_with_chains_controller.rb
lhs-21.2.3.pre.preload.pre.providers.pre.too.1 spec/dummy/app/controllers/error_handling_with_chains_controller.rb