开发者

Rescue Authentication Error while retrieving contacts from cardmagic/contacts gem

开发者 https://www.devze.com 2023-03-29 03:05 出处:网络
I am using cardmagic/contacts gem to import contacts from email addresses in my application. It is working fine but my problem is I want to catch the authentication error like wrong username/password

I am using cardmagic/contacts gem to import contacts from email addresses in my application. It is working fine but my problem is I want to catch the authentication error like wrong username/password for following code.

@contacts = Contacts.guess(@username, @password)

I want to display that error to user.

I have tried this but not working for me.

@contacts = Co开发者_开发百科ntacts.guess(@username, @password)  rescue Contacts::AuthenticationError  

So please guide me how to do so. Thank you.


def import
  @username = params[:user]
  @password = params[:pass]
  begin
    @contacts = Contacts.guess(@username, @password)  
  rescue
    @error_message = e.message
    render :action => 'new'
  end
  redirect_to root_path
end

new.html.erb:

<% if @error_message %>
  <%= @error_message %>
<% end %>
HTML to get username & password inputs
0

精彩评论

暂无评论...
验证码 换一张
取 消