1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace App\Exceptions; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Illuminate\Auth\AuthenticationException; |
7
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
8
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
9
|
|
|
use Facades\App\Services\WhichPortal; |
10
|
|
|
use Illuminate\Support\Facades\Lang; |
11
|
|
|
|
12
|
|
|
class Handler extends ExceptionHandler |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* A list of the exception types that are not reported. |
16
|
|
|
* |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
protected $dontReport = [ |
20
|
|
|
// |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* A list of the inputs that are never flashed for validation exceptions. |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $dontFlash = [ |
29
|
|
|
'password', |
30
|
|
|
'password_confirmation', |
31
|
|
|
'old_password', |
32
|
|
|
'new_password', |
33
|
|
|
'new_password_confirmation', |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Report or log an exception. |
38
|
|
|
* |
39
|
|
|
* @param \Exception $exception |
|
|
|
|
40
|
|
|
* @return void |
|
|
|
|
41
|
|
|
*/ |
42
|
2 |
|
public function report(Exception $exception) |
43
|
|
|
{ |
44
|
2 |
|
parent::report($exception); |
45
|
2 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Render an exception into an HTTP response. |
49
|
|
|
* |
50
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
51
|
|
|
* @param \Exception $exception |
|
|
|
|
52
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
53
|
|
|
*/ |
54
|
2 |
|
public function render($request, Exception $exception) |
55
|
|
|
{ |
56
|
2 |
|
return parent::render($request, $exception); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Convert an authentication exception into an unauthenticated response. |
61
|
|
|
* |
62
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
63
|
|
|
* @param \Illuminate\Auth\AuthenticationException $exception |
|
|
|
|
64
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
65
|
|
|
*/ |
66
|
|
|
protected function unauthenticated($request, AuthenticationException $exception) |
67
|
|
|
{ |
68
|
|
|
if ($request->expectsJson()) { |
69
|
|
|
return response()->json(['error' => 'Unauthenticated.'], 401); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
if (WhichPortal::isManagerPortal()) { |
72
|
|
|
$loginRoute = route('manager.login'); |
73
|
|
|
} else { |
74
|
|
|
$loginRoute = route('login'); |
75
|
|
|
} |
76
|
|
|
return redirect()->guest($loginRoute); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* OVERRIDE |
81
|
|
|
* Render the given HttpException. |
82
|
|
|
* |
83
|
|
|
* @param \Symfony\Component\HttpKernel\Exception\HttpException $e |
|
|
|
|
84
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
|
|
|
85
|
|
|
*/ |
86
|
|
|
protected function renderHttpException(HttpException $e) |
87
|
|
|
{ |
88
|
|
|
if (! view()->exists("errors.{$e->getStatusCode()}")) { |
89
|
|
|
return response()->view('errors.default', [ |
|
|
|
|
90
|
|
|
'exception' => $e, |
91
|
|
|
'goc' => Lang::get('common/goc'), |
92
|
|
|
'alert' => Lang::get('common/alert'), |
93
|
|
|
'error' => [ |
94
|
|
|
"title" => "Error" |
95
|
|
|
] |
96
|
|
|
], 500, $e->getHeaders()); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
return parent::renderHttpException($e); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|