Skip to content

Commit

Permalink
Better error handling and reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Nov 25, 2024
1 parent 69b45d4 commit 2bd8924
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
23 changes: 12 additions & 11 deletions lib/whimsy/sitestandards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,22 @@ def get_url(is_local = true)
# @return [hash of site data, crawl_time]
def get_sites(tlp = true)
local_copy = File.expand_path("#{get_url(true)}#{get_filename(tlp)}", __FILE__)
if File.exist? local_copy
crawl_time = File.mtime(local_copy).httpdate # show time in same format as last-mod
begin
begin
if File.exist? local_copy
crawl_time = File.mtime(local_copy).httpdate # show time in same format as last-mod
sites = JSON.parse(File.read(local_copy, :encoding => 'utf-8'))
rescue StandardError => e
else
require 'wunderbar'
Wunderbar.warn "Failed to read #{local_copy}: #{e.inspect}"
sites = {} # TODO temporary fix
Wunderbar.warn "Failed to find local copy #{local_copy}"
local_copy = "#{get_url(false)}#{get_filename(tlp)}"
response = Net::HTTP.get_response(URI(local_copy))
crawl_time = response['last-modified']
sites = JSON.parse(response.body)
end
else
rescue StandardError => e
require 'wunderbar'
Wunderbar.warn "Failed to find #{local_copy}"
response = Net::HTTP.get_response(URI("#{get_url(false)}#{get_filename(tlp)}"))
crawl_time = response['last-modified']
sites = JSON.parse(response.body)
Wunderbar.warn "Failed to parse #{local_copy}: #{e.inspect} #{e.backtrace.join("\n\t")}"
sites = {}
end
return sites, crawl_time
end
Expand Down
6 changes: 5 additions & 1 deletion www/site_or_pod.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@
}
) do
# Encapsulate data display (same for projects and podlings)
display_application(path_info, sites, analysis, checks_performed, cgi_for_tlps?)
if sites.size > 0
display_application(path_info, sites, analysis, checks_performed, cgi_for_tlps?)
else
_h3 'Could not parse the site data. Please check the error log for details.'
end
end

_script %{
Expand Down

0 comments on commit 2bd8924

Please sign in to comment.