Skip to content

Commit eef5c60

Browse files
committed
Fix bugsnag setUser
1 parent 0b1106d commit eef5c60

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

app/Exceptions/Handler.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
<?php
22
namespace Lio\Exceptions;
33

4+
use Bugsnag;
45
use Exception;
6+
use Illuminate\Contracts\Auth\Guard;
57
use Symfony\Component\HttpKernel\Exception\HttpException;
68
use Bugsnag\BugsnagLaravel\BugsnagExceptionHandler as ExceptionHandler;
79

810
class Handler extends ExceptionHandler
911
{
12+
/**
13+
* @var \Illuminate\Contracts\Auth\Guard
14+
*/
15+
private $auth;
16+
17+
/**
18+
* @param \Illuminate\Contracts\Auth\Guard $auth
19+
*/
20+
public function __construct(Guard $auth)
21+
{
22+
$this->auth = $auth;
23+
}
24+
1025
/**
1126
* A list of the exception types that should not be reported.
1227
*
@@ -26,6 +41,14 @@ class Handler extends ExceptionHandler
2641
*/
2742
public function report(Exception $e)
2843
{
44+
// If a user is logged in, we'll set him as the target user for which the errors will occur.
45+
if ($this->auth->check()) {
46+
Bugsnag::setUser([
47+
'name' => $this->auth->user()->name,
48+
'email' => $this->auth->user()->email,
49+
]);
50+
}
51+
2952
return parent::report($e);
3053
}
3154

app/Providers/AppServiceProvider.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ class AppServiceProvider extends ServiceProvider
1313
*/
1414
public function boot()
1515
{
16-
// If a user is logged in, we'll set him as the target user for which the errors will occur.
17-
if ($this->app['auth']->check()) {
18-
$this->app['bugsnag']->setUser([
19-
'name' => $this->app['auth']->user()->name,
20-
'email' => $this->app['auth']->user()->email
21-
]);
22-
}
16+
//
2317
}
2418

2519
/**

0 commit comments

Comments
 (0)