From e4c31075a8d00f09b0289fbb72ee3523871e9eb1 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 17 Feb 2024 07:47:17 +0900 Subject: [PATCH] fix: catch exception when cannot reach GitHub --- app/Controllers/Contribute.php | 6 ++++-- app/Controllers/Download.php | 6 ++++-- app/Controllers/Home.php | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Controllers/Contribute.php b/app/Controllers/Contribute.php index cd976775..8fdff2e9 100644 --- a/app/Controllers/Contribute.php +++ b/app/Controllers/Contribute.php @@ -2,7 +2,7 @@ namespace App\Controllers; -use Github\Exception\ExceptionInterface; +use Psr\Http\Client\ClientExceptionInterface; class Contribute extends BaseController { @@ -16,7 +16,9 @@ public function index() // Contributors are already sorted, so grab the first 12 $data['contributors'][$id] = array_slice($contributors, 0, 12); } - } catch (ExceptionInterface $e) { + } catch (ClientExceptionInterface $e) { + log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + $data['contributors'] = null; } diff --git a/app/Controllers/Download.php b/app/Controllers/Download.php index 0bcfe437..c1e01de7 100644 --- a/app/Controllers/Download.php +++ b/app/Controllers/Download.php @@ -2,7 +2,7 @@ namespace App\Controllers; -use Github\Exception\ExceptionInterface; +use Psr\Http\Client\ClientExceptionInterface; class Download extends BaseController { @@ -18,7 +18,9 @@ public function index() 'v3link' => end($releases['framework3'])->download_url, 'v4link' => end($releases['framework4'])->download_url, ]; - } catch (ExceptionInterface $e) { + } catch (ClientExceptionInterface $e) { + log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + $data = [ 'v3name' => 'unknown', 'v4name' => 'unknown', diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 610f063e..cd4f63be 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -2,7 +2,7 @@ namespace App\Controllers; -use Github\Exception\ExceptionInterface; +use Psr\Http\Client\ClientExceptionInterface; class Home extends BaseController { @@ -17,7 +17,9 @@ public function index() 'stargazers_count' => number_format($repos['codeigniter4']->stargazers_count), 'forks_count' => number_format($repos['codeigniter4']->forks_count), ]; - } catch (ExceptionInterface $e) { + } catch (ClientExceptionInterface $e) { + log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + $data = [ 'html_url' => 'https://github.com/codeigniter4/CodeIgniter4', 'stargazers_count' => '',