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

  • Home
  • SEARCH
  • 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 6154105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:12:23+00:00 2026-05-23T20:12:23+00:00

I have a tweets_controller #called when user submits twitter form def message unless current_user

  • 0

I have a tweets_controller

#called when user submits twitter form

def message
          unless current_user
            session[:twitter_message] = params[:twitter_message] #sets the message from the form so it's available for send_tweet in tweet.rb after we pass through omniauth
            redirect_to '/auth/twitter' #redirects to authorize via omniauth/twitter and create the user
          else
            @auth = Authorization.find_by_user_id(current_user)
            Tweet.update_status(@auth, params[:twitter_message])
            redirect_to edit_user_path(current_user), :notice => "Tweet sent."
          end
end

I’m trying to rescue when the status update fails. I want to display a flash message to the user, but — this is as far as I can seem to get:

def self.update_status(auth, msg)

     @token = auth.token
     @secret = auth.secret
     @message = msg
     @t = Twitter::Client.new

     Twitter.configure do |config|
       config.consumer_key = '[key]'
       config.consumer_secret = '[secret]'
       config.oauth_token = @token
       config.oauth_token_secret = @secret
       config.gateway = '[gateway_url]'
     end

     ret = @t.update(@message)
     tweet ||= Tweet.create_from_response(ret, auth.id)

    rescue Twitter::Error => e
      logger.error "#{e.message}."
end

How do I get the error message so I can display it to my user through 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-23T20:12:24+00:00Added an answer on May 23, 2026 at 8:12 pm

    You can create and throw a custom exception based on the application.

    In app/lib/could_not_update_status_error.rb

    class CouldNotUpdateStatusError < StandardError
    end
    

    Then in your model:

    rescue Twitter::Error => e
      logger.error "#{e.message}."
      raise CouldNotUpdateStatusError.new("Could not update status")
    

    And in your controller

    else
      begin
        @auth = Authorization.find_by_user_id(current_user)
        Tweet.update_status(@auth, params[:twitter_message])
        redirect_to edit_user_path(current_user), notice: "Tweet sent."
      rescue CoundNotUpdateStatusError => e
        # Do error stuff
    end
    

    Another option would be to do rescue return false in your Twitter::Error clause and wrap the update_status call in an if statement, however Exceptions are a more robust solution.

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

Sidebar

Related Questions

I have a silver light App that captures the tweets of certain Twitter user.
I have a very simple bit of jQuery to retrieve my latest Tweet $.getJSON(http://twitter.com/statuses/user_timeline/username.json?count=1,
I have a list of usernames on Twitter whose profiles are public. I wish
I have a list of tweets which I want to feed to twitter every
I have developed a simple site that fetches tweets from the Twitter public timeline,
I have a php Twitter app which lets you mark tweets as favorite. I'm
On twitter (new twitter) and facebook they now have the the ability to load
I have this function twitter_tweets_per_day($user, $rounding = 1) { // Helper function to calculate
I have created a twitter application and I need it to have Connect button
I have entities: Tweet and User . Tweet has an author , which is

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.