sarga/packages/Webkul/Admin/src/Exceptions/Handler.php

81 lines
3.0 KiB
PHP
Raw Normal View History

2018-10-17 07:40:08 +00:00
<?php
namespace Webkul\Admin\Exceptions;
use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\HttpException;
2018-10-25 08:07:21 +00:00
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\Eloquent\PDOException;
use Illuminate\Database\Eloquent\ErrorException;
2018-10-17 07:40:08 +00:00
class Handler extends ExceptionHandler
{
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
2018-11-29 12:09:39 +00:00
2018-10-17 07:40:08 +00:00
if ($exception instanceof HttpException) {
$statusCode = $exception->getStatusCode();
2018-10-25 08:07:21 +00:00
if (strpos($_SERVER['REQUEST_URI'], 'admin') !== false) {
2018-10-25 09:06:51 +00:00
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);
}
2018-10-25 08:07:21 +00:00
} else {
2018-10-25 09:06:51 +00:00
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);
}
2018-10-17 07:40:08 +00:00
}
2018-11-29 12:09:39 +00:00
} else if ($exception instanceof \ModelNotFoundException) {
2018-10-25 08:07:21 +00:00
if (strpos($_SERVER['REQUEST_URI'], 'admin') !== false){
return response()->view('admin::errors.404', [], 404);
}else {
return response()->view('shop::errors.404', [], 404);
}
2018-11-29 12:09:39 +00:00
} else if ($exception instanceof \PDOException) {
2018-10-25 08:07:21 +00:00
if (strpos($_SERVER['REQUEST_URI'], 'admin') !== false){
return response()->view('admin::errors.500', [], 500);
} else {
return response()->view('shop::errors.500', [], 500);
}
2018-10-17 07:40:08 +00:00
}
2018-11-29 12:09:39 +00:00
// else if ($exception instanceof \ErrorException) {
2018-10-25 08:07:21 +00:00
// if(strpos($_SERVER['REQUEST_URI'], 'admin') !== false){
// return response()->view('admin::errors.500', [], 500);
// }else {
// return response()->view('shop::errors.500', [], 500);
// }
// }
2018-10-17 07:40:08 +00:00
return parent::render($request, $exception);
}
}