Skip to content

Commit 64b92d4

Browse files
committed
Handle GitHub exceptions
1 parent 21ac84b commit 64b92d4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

app/Http/Controllers/Auth/GitHubController.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use App\Jobs\UpdateProfile;
77
use App\Models\User;
88
use App\Social\GitHubUser;
9+
use GuzzleHttp\Exception\ClientException;
10+
use GuzzleHttp\Exception\ServerException;
911
use Illuminate\Database\Eloquent\ModelNotFoundException;
1012
use Illuminate\Http\RedirectResponse;
1113
use Illuminate\Support\Facades\Auth;
@@ -47,7 +49,13 @@ public function handleProviderCallback()
4749

4850
private function getSocialiteUser(): SocialiteUser
4951
{
50-
return Socialite::driver('github')->user();
52+
try {
53+
return Socialite::driver('github')->user();
54+
} catch (ClientException|ServerException $e) {
55+
$this->error('An error occurred while trying to log in with GitHub. Please try again.');
56+
57+
return redirect()->route('login');
58+
}
5159
}
5260

5361
private function userFound(User $user, SocialiteUser $socialiteUser): RedirectResponse

0 commit comments

Comments
 (0)