Skip to content

Commit

Permalink
handled host unreachable exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhbir-singh committed Jun 6, 2019
1 parent 8d89165 commit 29c3f6d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 31 deletions.
2 changes: 0 additions & 2 deletions app/views/friendings/_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
- @user = User.new

= form_tag friendings_engine.create_friend_request_path,\
:remote => true,\
:method => :post,\
Expand Down
27 changes: 17 additions & 10 deletions app/views/friendings/index.html.slim
Original file line number Diff line number Diff line change
@@ -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'
42 changes: 25 additions & 17 deletions app/views/friendings/requests.html.slim
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 9 additions & 2 deletions lib/friendings/amahi_friending_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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", []
Expand All @@ -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", []
Expand Down

0 comments on commit 29c3f6d

Please sign in to comment.