Skip to content

Commit 33d7272

Browse files
author
Ashley Williams
committed
Merge pull request #66 from ashleygwilliams/master
rescuing httperrors so page doesn't fail when github is unavailable
2 parents ac5b5a4 + b739766 commit 33d7272

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

app.rb

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,40 +62,58 @@ def contributors_url
6262
end
6363

6464
def contributors
65-
JSON.parse(open(contributors_url).read)
65+
begin
66+
JSON.parse(open(contributors_url).read)
67+
rescue OpenURI::HTTPError => the_error
68+
puts "Whoops got a bad status code from github: #{the_error.message}"
69+
nil
70+
end
6671
end
6772

6873
def commits
69-
JSON.parse(open(commits_url).read)
74+
begin
75+
JSON.parse(open(commits_url).read)
76+
rescue OpenURI::HTTPError => the_error
77+
puts "Whoops got a bad status code from github: #{the_error.message}"
78+
nil
79+
end
7080
end
7181

7282
def get_authors
73-
commits.map do |x|
83+
if commits
84+
commits.map do |x|
7485
{
7586
:name => x['author']['login'],
7687
:avatar => x['author']['avatar_url'],
7788
:url => x['author']['html_url']
7889
}
79-
end.uniq.flatten.group_by {|x| x[:name]}
90+
end.uniq.flatten.group_by {|x| x[:name]}
91+
end
8092
end
8193

8294
def get_activity
83-
commits.map do |x|
84-
{
85-
:author_name => x['author']['login'],
86-
:merge_date => Time.parse(x['commit']['author']['date']).strftime("%d-%B-%Y"),
87-
:commit_message => x['commit']['message'],
88-
:commit_url => "https://github.com/sinatra/sinatra-recipes/commit/#{x['sha']}"
89-
}
90-
end.group_by {|x| x[:merge_date] }
95+
if commits
96+
commits.map do |x|
97+
{
98+
:author_name => x['author']['login'],
99+
:merge_date => Time.parse(x['commit']['author']['date']).strftime("%d-%B-%Y"),
100+
:commit_message => x['commit']['message'],
101+
:commit_url => "https://github.com/sinatra/sinatra-recipes/commit/#{x['sha']}"
102+
}
103+
end.group_by {|x| x[:merge_date] }
104+
else
105+
nil
106+
end
91107
end
92108

93109
def get_activity_by_author
94-
get_activity.map do |k,v|
95-
{
96-
:date => k,
97-
:activity_by_author => v.group_by {|z| z[:author_name] }
98-
}
110+
if get_activity
111+
get_activity.map do |k,v|
112+
{
113+
:date => k,
114+
:activity_by_author => v.group_by {|z| z[:author_name] }
115+
}
116+
end
99117
end
100118
end
101119
end
@@ -130,7 +148,11 @@ def get_activity_by_author
130148
pass if params[:topic] == '..'
131149
@authors = get_authors
132150
@activity = get_activity_by_author
133-
markdown :'activity/README'
151+
if @authors && @activity
152+
markdown :'activity/README'
153+
else
154+
"Not available at this time."
155+
end
134156
end
135157

136158
get '/style.css' do
@@ -224,7 +246,7 @@ def get_activity_by_author
224246
p
225247
| These recipes are provided by the following outstanding members of the Sinatra
226248
| community:
227-
dl id="contributors"
249+
dl id="contributors"
228250
- @contributors.each do |contributor|
229251
dt
230252
a href="http://github.com/#{contributor["login"]}"

0 commit comments

Comments
 (0)