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
|
5 |
|
public function report(Exception $exception) |
|
|
|
|
43
|
|
|
{ |
44
|
5 |
|
parent::report($exception); |
45
|
5 |
|
} |
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
|
5 |
|
public function render($request, Exception $exception) |
|
|
|
|
55
|
|
|
{ |
56
|
5 |
|
if ($exception instanceof AdminException) { |
57
|
|
|
return $exception->render($request); |
58
|
|
|
} |
59
|
5 |
|
return parent::render($request, $exception); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Convert an authentication exception into an unauthenticated response. |
64
|
|
|
* |
65
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
66
|
|
|
* @param \Illuminate\Auth\AuthenticationException $exception |
|
|
|
|
67
|
|
|
* @return \Illuminate\Http\Response |
68
|
|
|
*/ |
69
|
1 |
|
protected function unauthenticated($request, AuthenticationException $exception) |
|
|
|
|
70
|
|
|
{ |
71
|
1 |
|
if ($request->expectsJson()) { |
72
|
|
|
return response()->json(['error' => 'Unauthenticated.'], 401); |
|
|
|
|
73
|
|
|
} |
74
|
1 |
|
if (WhichPortal::isManagerPortal()) { |
75
|
|
|
$loginRoute = route('manager.login'); |
76
|
|
|
} else { |
77
|
1 |
|
$loginRoute = route('login'); |
78
|
|
|
} |
79
|
1 |
|
return redirect()->guest($loginRoute); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* OVERRIDE |
84
|
|
|
* Render the given HttpException. |
85
|
|
|
* |
86
|
|
|
* @param \Symfony\Component\HttpKernel\Exception\HttpException $e |
|
|
|
|
87
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
88
|
|
|
*/ |
89
|
3 |
|
protected function renderHttpException(HttpException $e) |
|
|
|
|
90
|
|
|
{ |
91
|
3 |
|
if (! view()->exists("errors.{$e->getStatusCode()}")) { |
92
|
3 |
|
return response()->view('errors.default', [ |
93
|
3 |
|
'exception' => $e, |
94
|
3 |
|
'goc' => Lang::get('common/goc'), |
95
|
3 |
|
'alert' => Lang::get('common/alert'), |
96
|
|
|
'error' => [ |
97
|
|
|
"title" => "Error" |
98
|
|
|
] |
99
|
3 |
|
], $e->getStatusCode(), $e->getHeaders()); |
100
|
|
|
} |
101
|
|
|
return parent::renderHttpException($e); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|