Skip to content

Instantly share code, notes, and snippets.

@stevepolitodesign
Last active February 2, 2022 19:49
Show Gist options
  • Save stevepolitodesign/41614d36f8e97b172a10c0382bfaf6aa to your computer and use it in GitHub Desktop.
Save stevepolitodesign/41614d36f8e97b172a10c0382bfaf6aa to your computer and use it in GitHub Desktop.
Raise error that need to be handled manually

Intentionally raise an error that needs to be handled manually

Sometimes there are cases when an actual human needs to intervene during edge cases.

# app/lib/manual_intervention_error.rb
class ManualInterventionError < StandardError
  def initialize(message = "An error occured that needs to be addressed manually")
    super
  end
end
class AppointmentsController < ApplicationController
  rescue_from ManualInterventionError, with: :redirect_and_email_support

  def create
    if some_unique_condition
      raise ManualInterventionError
    end
  end
  
  private
  
  def redirect_and_email_support
    redirect_to root_path, alert: "There was an unexpected error. We have notified support."
    ErrorMailer.generic_error.deliver_later
  end
  
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment