|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* NOTICE OF LICENSE |
|
5
|
|
|
* |
|
6
|
|
|
* Part of the Rinvex Fort Package. |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to The MIT License (MIT) |
|
9
|
|
|
* that is bundled with this package in the LICENSE file. |
|
10
|
|
|
* |
|
11
|
|
|
* Package: Rinvex Fort Package |
|
12
|
|
|
* License: The MIT License (MIT) |
|
13
|
|
|
* Link: https://rinvex.com |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Rinvex\Fort\Exceptions; |
|
17
|
|
|
|
|
18
|
|
|
use Exception; |
|
19
|
|
|
use Illuminate\Support\Facades\Lang; |
|
20
|
|
|
use Illuminate\Auth\AuthenticationException; |
|
21
|
|
|
use App\Exceptions\Handler as ExceptionHandler; |
|
22
|
|
|
use Rinvex\Repository\Exceptions\EntityNotFoundException; |
|
23
|
|
|
|
|
24
|
|
|
class Handler extends ExceptionHandler |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Render an exception into an HTTP response. |
|
28
|
|
|
* |
|
29
|
|
|
* @param \Illuminate\Http\Request $request |
|
30
|
|
|
* @param \Exception $exception |
|
31
|
|
|
* |
|
32
|
|
|
* @return \Illuminate\Http\Response |
|
33
|
|
|
*/ |
|
34
|
|
|
public function render($request, Exception $exception) |
|
35
|
|
|
{ |
|
36
|
|
|
if ($exception instanceof InvalidPersistenceException) { |
|
37
|
|
|
return intend([ |
|
38
|
|
|
'route' => 'rinvex.fort.frontend.auth.login', |
|
39
|
|
|
'withErrors' => ['rinvex.fort.session.expired' => Lang::get('rinvex.fort::frontend/messages.auth.session.expired')], |
|
|
|
|
|
|
40
|
|
|
], 401); |
|
41
|
|
|
} else if ($exception instanceof EntityNotFoundException) { |
|
42
|
|
|
$single = strtolower(trim(strrchr($exception->getModel(), '\\'), '\\')); |
|
43
|
|
|
$plural = str_plural($single); |
|
44
|
|
|
|
|
45
|
|
|
return intend([ |
|
46
|
|
|
'route' => 'rinvex.fort.backend.'.$plural.'.index', |
|
47
|
|
|
'withErrors' => ['rinvex.fort.'.$single.'.not_found' => trans('rinvex.fort::backend/messages.'.$single.'.not_found', [$single => $exception->getId()])], |
|
|
|
|
|
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return parent::render($request, $exception); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Convert an authentication exception into an unauthenticated response. |
|
56
|
|
|
* |
|
57
|
|
|
* @param \Illuminate\Http\Request $request |
|
58
|
|
|
* @param \Illuminate\Auth\AuthenticationException $exception |
|
59
|
|
|
* |
|
60
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
61
|
|
|
*/ |
|
62
|
|
|
protected function unauthenticated($request, AuthenticationException $exception) |
|
63
|
|
|
{ |
|
64
|
|
|
return intend([ |
|
65
|
|
|
'route' => 'rinvex.fort.frontend.auth.login', |
|
66
|
|
|
'withErrors' => ['rinvex.fort.session.required' => Lang::get('rinvex.fort::frontend/messages.auth.session.required')], |
|
|
|
|
|
|
67
|
|
|
], 401); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.