Fix timeout bug.
This commit is contained in:
parent
d324d141d0
commit
1ef665007a
|
@ -24,6 +24,8 @@ module RulingBusesHelper
|
|||
|
||||
include HTTParty
|
||||
base_uri 'https://ptx.transportdata.tw/MOTC/v2'
|
||||
open_timeout 3
|
||||
read_timeout 1
|
||||
format :json
|
||||
|
||||
headers(
|
||||
|
@ -125,7 +127,11 @@ module RulingBusesHelper
|
|||
'(' + v.map{|r| "RouteName/#{bus_info.locale} eq '#{r}'"}.join(' or ') + '))')
|
||||
end.join(' or ')
|
||||
url = "/Bus/EstimatedTimeOfArrival/City/#{city}?$select=Direction,RouteName,NextBusTime&$filter=#{filters}&$format=JSON&$orderby=RouteName/#{locale}"
|
||||
bus_data = JSON.parse(self.get(url).body)
|
||||
begin
|
||||
bus_data = JSON.parse(self.get(url).body)
|
||||
rescue Errno::EHOSTUNREACH, Net::ReadTimeout, Net::OpenTimeout
|
||||
return nil
|
||||
end
|
||||
if bus_data.class==Hash
|
||||
return nil
|
||||
end
|
||||
|
@ -135,7 +141,11 @@ module RulingBusesHelper
|
|||
'(' + v.map{|r| "RouteName/#{bus_info.locale} eq '#{r}'"}.join(' or ') + '))')
|
||||
end.join(' or ')
|
||||
url2 = "/Bus/EstimatedTimeOfArrival/InterCity?$select=Direction,RouteName,NextBusTime&$filter=#{filters}&$format=JSON&$orderby=RouteName/#{locale}"
|
||||
pbus_data = JSON.parse(self.get(url2).body)
|
||||
begin
|
||||
pbus_data = JSON.parse(self.get(url2).body)
|
||||
rescue Errno::EHOSTUNREACH, Net::ReadTimeout, Net::OpenTimeout
|
||||
pbus_data = []
|
||||
end
|
||||
else
|
||||
pbus_data = []
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue