Skip to content

Commit

Permalink
fix: catch exception when cannot reach GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Feb 16, 2024
1 parent 624291d commit e4c3107
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions app/Controllers/Contribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Controllers;

use Github\Exception\ExceptionInterface;
use Psr\Http\Client\ClientExceptionInterface;

class Contribute extends BaseController
{
Expand All @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions app/Controllers/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Controllers;

use Github\Exception\ExceptionInterface;
use Psr\Http\Client\ClientExceptionInterface;

class Download extends BaseController
{
Expand All @@ -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' => '<em>unknown</em>',
'v4name' => '<em>unknown</em>',
Expand Down
6 changes: 4 additions & 2 deletions app/Controllers/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Controllers;

use Github\Exception\ExceptionInterface;
use Psr\Http\Client\ClientExceptionInterface;

class Home extends BaseController
{
Expand All @@ -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());

Check warning on line 21 in app/Controllers/Home.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "Concat": --- Original +++ New @@ @@ $repos = $this->github->getRepos(); $data = ['html_url' => $repos['framework4']->html_url, 'stargazers_count' => number_format($repos['codeigniter4']->stargazers_count), 'forks_count' => number_format($repos['codeigniter4']->forks_count)]; } catch (ClientExceptionInterface $e) { - log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + log_message('error', __METHOD__ . '[' . '] ' . get_class($e) . ': ' . $e->getMessage()); $data = ['html_url' => 'https://github.com/codeigniter4/CodeIgniter4', 'stargazers_count' => '', 'forks_count' => '']; } echo $this->render('home', $data); } }

Check warning on line 21 in app/Controllers/Home.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ $repos = $this->github->getRepos(); $data = ['html_url' => $repos['framework4']->html_url, 'stargazers_count' => number_format($repos['codeigniter4']->stargazers_count), 'forks_count' => number_format($repos['codeigniter4']->forks_count)]; } catch (ClientExceptionInterface $e) { - log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + log_message('error', __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); $data = ['html_url' => 'https://github.com/codeigniter4/CodeIgniter4', 'stargazers_count' => '', 'forks_count' => '']; } echo $this->render('home', $data); } }

Check warning on line 21 in app/Controllers/Home.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ $repos = $this->github->getRepos(); $data = ['html_url' => $repos['framework4']->html_url, 'stargazers_count' => number_format($repos['codeigniter4']->stargazers_count), 'forks_count' => number_format($repos['codeigniter4']->forks_count)]; } catch (ClientExceptionInterface $e) { - log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + log_message('error', '[' . '] ' . get_class($e) . ': ' . $e->getMessage()); $data = ['html_url' => 'https://github.com/codeigniter4/CodeIgniter4', 'stargazers_count' => '', 'forks_count' => '']; } echo $this->render('home', $data); } }

Check warning on line 21 in app/Controllers/Home.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "Concat": --- Original +++ New @@ @@ $repos = $this->github->getRepos(); $data = ['html_url' => $repos['framework4']->html_url, 'stargazers_count' => number_format($repos['codeigniter4']->stargazers_count), 'forks_count' => number_format($repos['codeigniter4']->forks_count)]; } catch (ClientExceptionInterface $e) { - log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + log_message('error', '[' . '] ' . __METHOD__ . get_class($e) . ': ' . $e->getMessage()); $data = ['html_url' => 'https://github.com/codeigniter4/CodeIgniter4', 'stargazers_count' => '', 'forks_count' => '']; } echo $this->render('home', $data); } }

Check warning on line 21 in app/Controllers/Home.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ $repos = $this->github->getRepos(); $data = ['html_url' => $repos['framework4']->html_url, 'stargazers_count' => number_format($repos['codeigniter4']->stargazers_count), 'forks_count' => number_format($repos['codeigniter4']->forks_count)]; } catch (ClientExceptionInterface $e) { - log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + log_message('error', '[' . __METHOD__ . get_class($e) . ': ' . $e->getMessage()); $data = ['html_url' => 'https://github.com/codeigniter4/CodeIgniter4', 'stargazers_count' => '', 'forks_count' => '']; } echo $this->render('home', $data); } }

Check warning on line 21 in app/Controllers/Home.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "Concat": --- Original +++ New @@ @@ $repos = $this->github->getRepos(); $data = ['html_url' => $repos['framework4']->html_url, 'stargazers_count' => number_format($repos['codeigniter4']->stargazers_count), 'forks_count' => number_format($repos['codeigniter4']->forks_count)]; } catch (ClientExceptionInterface $e) { - log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + log_message('error', '[' . __METHOD__ . get_class($e) . '] ' . ': ' . $e->getMessage()); $data = ['html_url' => 'https://github.com/codeigniter4/CodeIgniter4', 'stargazers_count' => '', 'forks_count' => '']; } echo $this->render('home', $data); } }

Check warning on line 21 in app/Controllers/Home.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ $repos = $this->github->getRepos(); $data = ['html_url' => $repos['framework4']->html_url, 'stargazers_count' => number_format($repos['codeigniter4']->stargazers_count), 'forks_count' => number_format($repos['codeigniter4']->forks_count)]; } catch (ClientExceptionInterface $e) { - log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + log_message('error', '[' . __METHOD__ . '] ' . ': ' . $e->getMessage()); $data = ['html_url' => 'https://github.com/codeigniter4/CodeIgniter4', 'stargazers_count' => '', 'forks_count' => '']; } echo $this->render('home', $data); } }

Check warning on line 21 in app/Controllers/Home.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "Concat": --- Original +++ New @@ @@ $repos = $this->github->getRepos(); $data = ['html_url' => $repos['framework4']->html_url, 'stargazers_count' => number_format($repos['codeigniter4']->stargazers_count), 'forks_count' => number_format($repos['codeigniter4']->forks_count)]; } catch (ClientExceptionInterface $e) { - log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + log_message('error', '[' . __METHOD__ . '] ' . ': ' . get_class($e) . $e->getMessage()); $data = ['html_url' => 'https://github.com/codeigniter4/CodeIgniter4', 'stargazers_count' => '', 'forks_count' => '']; } echo $this->render('home', $data); } }

Check warning on line 21 in app/Controllers/Home.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ $repos = $this->github->getRepos(); $data = ['html_url' => $repos['framework4']->html_url, 'stargazers_count' => number_format($repos['codeigniter4']->stargazers_count), 'forks_count' => number_format($repos['codeigniter4']->forks_count)]; } catch (ClientExceptionInterface $e) { - log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . $e->getMessage()); $data = ['html_url' => 'https://github.com/codeigniter4/CodeIgniter4', 'stargazers_count' => '', 'forks_count' => '']; } echo $this->render('home', $data); } }

Check warning on line 21 in app/Controllers/Home.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "Concat": --- Original +++ New @@ @@ $repos = $this->github->getRepos(); $data = ['html_url' => $repos['framework4']->html_url, 'stargazers_count' => number_format($repos['codeigniter4']->stargazers_count), 'forks_count' => number_format($repos['codeigniter4']->forks_count)]; } catch (ClientExceptionInterface $e) { - log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . ': ' . $e->getMessage()); + log_message('error', '[' . __METHOD__ . '] ' . get_class($e) . $e->getMessage() . ': '); $data = ['html_url' => 'https://github.com/codeigniter4/CodeIgniter4', 'stargazers_count' => '', 'forks_count' => '']; } echo $this->render('home', $data); } }

$data = [
'html_url' => 'https://github.com/codeigniter4/CodeIgniter4',
'stargazers_count' => '',
Expand Down

0 comments on commit e4c3107

Please sign in to comment.