Skip to content

Commit

Permalink
Add timeout and error handling to credits lookup for dashboard #6
Browse files Browse the repository at this point in the history
  • Loading branch information
sedan07 authored and Seb Dangerfield committed Jan 28, 2021
1 parent 1860bac commit 2e43e2d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/Http/Controllers/Dashboard/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,20 @@ public function showCreditsView()

$credits = app(Credits::class)->latest();

$backers = $credits['backers'];
$contributors = $credits['contributors'];
if ($credits) {
$backers = $credits['backers'];
$contributors = $credits['contributors'];

shuffle($backers);
shuffle($contributors);
shuffle($backers);
shuffle($contributors);
}

return View::make('dashboard.settings.credits')
->withPageTitle(trans('dashboard.settings.credits.credits').' - '.trans('dashboard.dashboard'))
->withBackers($backers)
->withContributors($contributors)
->withSubMenu($this->subMenu);
->withBackers(($credits) ? $backers : false)
->withContributors(($credits) ? $contributors : false)
->withSubMenu($this->subMenu)
->withErrors((!$credits) ? trans('dashboard.settings.credits.unable-to-load') : null);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions app/Integrations/Core/Credits.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public function latest()
try {
return json_decode((new Client())->get($this->url, [
'headers' => ['Accept' => 'application/json', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'],
'timeout' => 5,
'connect_timeout' => 5,
])->getBody(), true);
} catch (Exception $e) {
return self::FAILED;
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
'backers-title' => 'Backers & Sponsors',
'backers' => 'If you\'d like to support future development, check out the <a href="https://patreon.com/jbrooksuk" target="_blank">Cachet Patreon</a> campaign.',
'thank-you' => 'Thank you to each and every one of the :count contributors.',
'unable-to-load'=> 'Unable to load details about contributors and sponsors.'
],
],

Expand Down
3 changes: 3 additions & 0 deletions resources/views/dashboard/settings/credits.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
</div>
<div class="row">
<div class="col-sm-12">
@include('partials.errors')
<h4>Cachet</h4>

<p>{!! trans('dashboard.settings.credits.license') !!}</p>

<hr>
@if($contributors)

<h4>{{ trans('dashboard.settings.credits.contributors') }}</h4>

Expand All @@ -30,6 +32,7 @@
</li>
@endforeach
</ul>
@endif

<hr>
</div>
Expand Down

0 comments on commit 2e43e2d

Please sign in to comment.