Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 886129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:01:10+00:00 2026-05-15T13:01:10+00:00

I am currently involved in the development of a large rails application that interfaces

  • 0

I am currently involved in the development of a large rails application that interfaces with another product via a custom API gem. This has led to a very strange sort of error catching. For instance, when we interact with the other product, it might return an authentication error, which we expect. We then catch that error in our API gem and throw an exception, which is then caught and relayed to the user in the view.

I do not like this method of error catching for a few reasons:

  • It doesn’t seem like we should be expecting exceptions and using them in our logic. As an example, sometimes we want to overwrite an object — so we catch the “object already exists” exception and go ahead and save our model anyway.
  • It requires a lot of specific error catching. There are multiple areas in the code where we have if-elses checking for certain errors and redirecting accordingly.

That said, should I flesh out the API gem to have simpler functions that do not throw exceptions? Is

if user.has_permission_in_product?
  if object.doesnt_exist_in_product?
    do something
  else
    redirect somewhere with errors
  end
else
  redirect somewhere else with errors
end

preferable to

begin
  do something
rescue APIError => e
  if e.message =~ "no permission"
    redirect somewhere with errors
  elsif e.message =~ "already exists"
    redirect somewhere else with errors
  end
end

Furthermore, if the first is preferable, how do we deal with actual API errors that may be thrown in those functions? Do we bubble those up into a rescue_from in the controller?

Is it better to catch and deal with exceptions in the model, or throw them in the model and deal with them in the controller?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:01:11+00:00Added an answer on May 15, 2026 at 1:01 pm

    Are you looking for rescue_from ?

    In your controller, do the following :

    class MyController < ApplicationController
        rescue_from ActiveRecord::RecordNotFound, :with => :render_missing
    
        def render_missing
            render 'This is a 404', :status => 404
        end
    end
    

    This will execute the render_missing method every time an ActiveRecord::RecordNotFound exception is raised.
    You can use it with any exception class you wish. And you don’t need any begin/rescue in your controllers anymore.

    Of course any exception raised in a model could also be caught by rescue_from.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say that you get involved in the development of a large project that
I'm currently involved in a heavily localised WPF application and we've had a bug
I'm currently working on my Bachelors dissertation. This involves developing a software product and
I'm currently involved in a large project - the redevelopment of a corporate website.
I am currently involved in the development of a software using distributed computing to
I'm brand new to Ruby/Rails/RSpec, and hopefully this is a dumb/simple question. I'm currently
I currently have a school assignment that involves both PHP and asp.net. Now the
I'm currently designing a program that will involve some physics (nothing too fancy, a
I am currently undertaking a project that involves extensive use of Java RMI and
We are currently using a somewhat complicated deployment setup that involves a remote SVN

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.