From 3c75fb27c49c13b27c99a3d829fb396bfbaf7464 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Thu, 9 Jun 2016 12:23:50 +0200 Subject: [PATCH] Fix bug get Forbidden last version github --- app/views/root/landing.html.haml | 12 ++++++++---- lib/github/api.rb | 4 +++- lib/github/releases.rb | 4 +++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/views/root/landing.html.haml b/app/views/root/landing.html.haml index fdcbfbdba..700c56814 100644 --- a/app/views/root/landing.html.haml +++ b/app/views/root/landing.html.haml @@ -58,10 +58,14 @@ .row.word.news .latest_release.col-md-7.col-lg-7 - %h3.text-info - = "Dernière version (#{@latest_release.tag_name} - #{@latest_release.published_at})" - .body - =@latest_release.body.html_safe + - if @latest_release.nil? + %p + Erreur dans la récupération des données + -else + %h3.text-info + = "Dernière version (#{@latest_release.tag_name} - #{@latest_release.published_at})" + .body + =@latest_release.body.html_safe .center \- diff --git a/lib/github/api.rb b/lib/github/api.rb index 57c815fb7..8aab0ce86 100644 --- a/lib/github/api.rb +++ b/lib/github/api.rb @@ -12,7 +12,9 @@ class Github::API def self.call(end_point, params = {}) RestClient::Resource.new( - base_uri+end_point + base_uri+end_point, timeout: 5 ).get(params: params) + rescue RestClient::Forbidden + nil end end diff --git a/lib/github/releases.rb b/lib/github/releases.rb index f58f66b20..f71449b66 100644 --- a/lib/github/releases.rb +++ b/lib/github/releases.rb @@ -2,8 +2,10 @@ class Github::Releases def self.latest release = Hashie::Mash.new JSON.parse(Github::API.latest_release) - release.published_at = release.published_at.to_date.strftime('%d/%m/%Y') + return nil if release.nil? + + release.published_at = release.published_at.to_date.strftime('%d/%m/%Y') release end end \ No newline at end of file