Merge pull request #256 from AliN11/master
Optimized and minified ExceptionHandler
This commit is contained in:
commit
4977428cca
|
|
@ -4,11 +4,11 @@ namespace Webkul\Admin\Exceptions;
|
|||
|
||||
use Exception;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Database\Eloquent\PDOException;
|
||||
use Illuminate\Database\Eloquent\ErrorException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
|
|
@ -22,60 +22,38 @@ class Handler extends ExceptionHandler
|
|||
*/
|
||||
public function render($request, Exception $exception)
|
||||
{
|
||||
$path = $this->isAdminUri() ? 'admin' : 'shop';
|
||||
|
||||
if ($exception instanceof HttpException) {
|
||||
$statusCode = $exception->getStatusCode();
|
||||
if (strpos($_SERVER['REQUEST_URI'], 'admin') !== false) {
|
||||
switch ($statusCode) {
|
||||
case 404:
|
||||
return response()->view('admin::errors.404', [], 404);
|
||||
break;
|
||||
case 403:
|
||||
return response()->view('admin::errors.403', [], 403);
|
||||
break;
|
||||
case 401:
|
||||
return response()->view('admin::errors.401', [], 401);
|
||||
break;
|
||||
default:
|
||||
return response()->view('admin::errors.500', [], 500);
|
||||
}
|
||||
} else {
|
||||
switch ($statusCode) {
|
||||
case 404:
|
||||
return response()->view('shop::errors.404', [], 404);
|
||||
break;
|
||||
case 403:
|
||||
return response()->view('shop::errors.403', [], 403);
|
||||
break;
|
||||
case 401:
|
||||
return response()->view('shop::errors.401', [], 401);
|
||||
break;
|
||||
default:
|
||||
return response()->view('shop::errors.500', [], 500);
|
||||
}
|
||||
}
|
||||
} else if ($exception instanceof \ModelNotFoundException) {
|
||||
if (strpos($_SERVER['REQUEST_URI'], 'admin') !== false){
|
||||
return response()->view('admin::errors.404', [], 404);
|
||||
}else {
|
||||
return response()->view('shop::errors.404', [], 404);
|
||||
}
|
||||
} else if ($exception instanceof \PDOException) {
|
||||
if (strpos($_SERVER['REQUEST_URI'], 'admin') !== false){
|
||||
return response()->view('admin::errors.500', [], 500);
|
||||
} else {
|
||||
return response()->view('shop::errors.500', [], 500);
|
||||
}
|
||||
$statusCode = in_array($statusCode, [401, 403, 404]) ? $statusCode : 500;
|
||||
return $this->response($path, $statusCode);
|
||||
} else if ($exception instanceof ModelNotFoundException) {
|
||||
return $this->response($path, 404);
|
||||
} else if ($exception instanceof PDOException) {
|
||||
return $this->response($path, 500);
|
||||
}
|
||||
// else if ($exception instanceof \ErrorException) {
|
||||
// else if ($exception instanceof ErrorException) {
|
||||
|
||||
// if(strpos($_SERVER['REQUEST_URI'], 'admin') !== false){
|
||||
// return response()->view('admin::errors.500', [], 500);
|
||||
// }else {
|
||||
// return response()->view('shop::errors.500', [], 500);
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
|
||||
private function isAdminUri()
|
||||
{
|
||||
return strpos($_SERVER['REQUEST_URI'], 'admin') !== false ? true : false;
|
||||
}
|
||||
|
||||
private function response($path, $statusCode)
|
||||
{
|
||||
return response()->view("{$path}::errors.{$statusCode}", [], $statusCode);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue