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

59 lines
1.9 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;
2018-10-25 08:07:21 +00:00
use Illuminate\Database\Eloquent\PDOException;
use Illuminate\Database\Eloquent\ErrorException;
2018-12-01 10:03:32 +00:00
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
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-12-01 10:03:32 +00:00
$path = $this->isAdminUri() ? 'admin' : 'shop';
2018-11-29 12:09:39 +00:00
2018-10-17 07:40:08 +00:00
if ($exception instanceof HttpException) {
$statusCode = $exception->getStatusCode();
2018-12-01 10:03:32 +00:00
$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);
2018-10-17 07:40:08 +00:00
}
2018-12-01 10:03:32 +00:00
// else if ($exception instanceof ErrorException) {
2018-10-25 08:07:21 +00:00
2019-01-15 12:02:43 +00:00
// if (strpos($_SERVER['REQUEST_URI'], 'admin') !== false) {
2018-10-25 08:07:21 +00:00
// return response()->view('admin::errors.500', [], 500);
// }else {
// return response()->view('shop::errors.500', [], 500);
// }
2018-12-01 10:03:32 +00:00
2018-10-25 08:07:21 +00:00
// }
2018-10-17 07:40:08 +00:00
return parent::render($request, $exception);
}
2018-12-01 10:03:32 +00:00
private function isAdminUri()
{
return strpos($_SERVER['REQUEST_URI'], 'admin') !== false ? true : false;
}
private function response($path, $statusCode)
{
return response()->view("{$path}::errors.{$statusCode}", [], $statusCode);
}
2018-10-17 07:40:08 +00:00
}