From 29c3f6d022cc87b17dd65b309a187b8929ffb2c8 Mon Sep 17 00:00:00 2001 From: sukhbir-singh Date: Thu, 6 Jun 2019 16:32:37 +0530 Subject: [PATCH] handled host unreachable exceptions --- app/views/friendings/_form.html.slim | 2 -- app/views/friendings/index.html.slim | 27 ++++++++++------ app/views/friendings/requests.html.slim | 42 +++++++++++++++---------- config/locales/en.yml | 2 ++ lib/friendings/amahi_friending_api.rb | 11 +++++-- 5 files changed, 53 insertions(+), 31 deletions(-) diff --git a/app/views/friendings/_form.html.slim b/app/views/friendings/_form.html.slim index b6f08ad..0a92f49 100644 --- a/app/views/friendings/_form.html.slim +++ b/app/views/friendings/_form.html.slim @@ -1,5 +1,3 @@ -- @user = User.new - = form_tag friendings_engine.create_friend_request_path,\ :remote => true,\ :method => :post,\ diff --git a/app/views/friendings/index.html.slim b/app/views/friendings/index.html.slim index cf2818c..7cefb7a 100755 --- a/app/views/friendings/index.html.slim +++ b/app/views/friendings/index.html.slim @@ -1,17 +1,24 @@ .settings-table#users-table - - if @users.any? - table.settings - thead - tr - th.settings-col1[scope="col"]= t('email') - th[scope="col"]= t('username') - th.settings-col1[scope="col"]= t('created_at') - - @users.each do |user| - = render 'user', friend_user: user + - if @status == "success" + - if @users.any? + table.settings + thead + tr + th.settings-col1[scope="col"]= t('email') + th[scope="col"]= t('username') + th.settings-col1[scope="col"]= t('created_at') + - @users.each do |user| + = render 'user', friend_user: user + - else + .no-users + h2= t('no_friend_users') + - elsif @status == "host_unreachable" + .no-users + h2= t('network_problem') - else .no-users - h2= t('no_friend_users') + h2= t('some_error_occurred') = stylesheet_link_tag 'friendings' = javascript_include_tag 'friendings' \ No newline at end of file diff --git a/app/views/friendings/requests.html.slim b/app/views/friendings/requests.html.slim index b4d6538..b2714cf 100755 --- a/app/views/friendings/requests.html.slim +++ b/app/views/friendings/requests.html.slim @@ -1,25 +1,33 @@ .settings-table#requests-table - - if @requests.any? - table.settings - thead - tr - th.settings-col1[scope="col"]= t('email') - th[scope="col", style="line-height: 20px"] = t('last_request_sent_at') - th.pr-3[scope="col"]= t('status') - th.settings-col1[scope="col"]= t('action') - - @requests.each do |request| - = render 'request', friend_request: request + - if @status == "success" + - if @requests.any? + table.settings + thead + tr + th.settings-col1[scope="col"]= t('email') + th[scope="col", style="line-height: 20px"] = t('last_request_sent_at') + th.pr-3[scope="col"]= t('status') + th.settings-col1[scope="col"]= t('action') + - @requests.each do |request| + = render 'request', friend_request: request + - else + .no-requests + h2= t('no_friending_requests') + - elsif @status == "host_unreachable" + .no-requests + h2= t('network_problem') - else - .no-requests - h2= t('no_friending_requests') + .no-requests + h2= t('some_error_occurred') -= button_tag t('add_new_friend_user'), :type => 'button', :class => 'open-area btnn btn-create btn btn-info pull-left', :id => "new-user-to-step1", :data => { :related => "#new-user-step1" } +- if @status == "success" + = button_tag t('add_new_friend_user'), :type => 'button', :class => 'open-area btnn btn-create btn btn-info pull-left', :id => "new-user-to-step1", :data => { :related => "#new-user-step1" } -#new-user-box.col-sm-7 - #user-new - #new-user-step1.area[style="display:none;"] - = render 'form' + #new-user-box.col-sm-7 + #user-new + #new-user-step1.area[style="display:none;"] + = render 'form' = javascript_include_tag 'friendings' = stylesheet_link_tag 'friendings' diff --git a/config/locales/en.yml b/config/locales/en.yml index 88e620e..069c507 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -13,3 +13,5 @@ created_at: Created At no_friending_requests: No Friending Requests resend: Resend + network_problem: Problem in connecting to the server + some_error_occurred: Some error occurred diff --git a/lib/friendings/amahi_friending_api.rb b/lib/friendings/amahi_friending_api.rb index c8b032c..b7002e3 100644 --- a/lib/friendings/amahi_friending_api.rb +++ b/lib/friendings/amahi_friending_api.rb @@ -3,7 +3,7 @@ require 'rest-client' class AmahiFriendingApi - BASE_URL = "http://66.165.251.200:8877/api/frnd" + BASE_URL = "http://66.165.251.203:8877/api/frnd" APIKEY = Setting.where({name: "api-key"}).first.value def self.get_friend_users @@ -28,7 +28,7 @@ def self.get_friend_users # case when NAU is deleted by admin and so probably admin do not want this # NAU as friend user and thus this user needs to be deleted from amahi.org - self.delete_user(user["amahi_user"]["id"], nil) + self.delete_user(user["amahi_user"]["id"], nil, "") else # case when remote user is present as NAU on platform @@ -62,6 +62,9 @@ def self.get_friend_users return "success", data + rescue Errno::EHOSTUNREACH + return "host_unreachable", [] + rescue RestClient::ExceptionWithResponse => err err.response return "failed", [] @@ -74,6 +77,10 @@ def self.get_friend_requests response = RestClient.get(url, headers={"Api-Key" => APIKEY}) json = JSON.parse(response) return "success", json + + rescue Errno::EHOSTUNREACH + return "host_unreachable", [] + rescue RestClient::ExceptionWithResponse => err err.response return "failed", []