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

67 lines
2.3 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-10-25 08:28:06 +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 08:28:06 +00:00
return response(view('admin::errors.'.$statusCode, [
2018-10-17 07:40:08 +00:00
'msg' => $exception->getMessage(),
'code' => $statusCode
]), $statusCode);
2018-10-25 08:07:21 +00:00
} else {
2018-10-25 08:28:06 +00:00
return response(view('shop::errors.'.$statusCode, [
2018-10-17 07:40:08 +00:00
'msg' => $exception->getMessage(),
'code' => $statusCode
]), $statusCode);
}
2018-10-25 08:07:21 +00:00
} 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) {
2018-10-17 07:40:08 +00:00
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-10-25 08:07:21 +00:00
// 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);
// }
// }
2018-10-17 07:40:08 +00:00
return parent::render($request, $exception);
}
}