update v1.0.7.9 R.C.
This is a Release Candidate. We are still testing.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
// controller
|
||||
use Bugsnag;
|
||||
//use Illuminate\Validation\ValidationException;
|
||||
@@ -13,7 +11,6 @@ use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Validation\ValidationException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
@@ -23,26 +20,13 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
protected $dontReport = [
|
||||
// 'Symfony\Component\HttpKernel\Exception\HttpException',
|
||||
Illuminate\Http\Exception\HttpResponseException::class,
|
||||
\Illuminate\Http\Exception\HttpResponseException::class,
|
||||
ValidationException::class,
|
||||
AuthorizationException::class,
|
||||
HttpResponseException ::class,
|
||||
ModelNotFoundException::class,
|
||||
\Symfony\Component\HttpKernel\Exception\HttpException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
* constructor to check
|
||||
* 1. php mailer.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
// public function __construct(PhpMailController $PhpMailController)
|
||||
// {
|
||||
// $this->PhpMailController = $PhpMailController;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
@@ -60,73 +44,12 @@ class Handler extends ExceptionHandler
|
||||
Bugsnag::setBeforeNotifyFunction(function ($error) {
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
$version = \Config::get('app.version');
|
||||
Bugsnag::setAppVersion($version);
|
||||
}
|
||||
|
||||
return parent::report($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Exception $e
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
// public function render($request, Exception $e) {
|
||||
// if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException) {
|
||||
// return response()->json(['message' => $e->getMessage(), 'code' => $e->getStatusCode()]);
|
||||
// } elseif ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException) {
|
||||
// return response()->json(['message' => $e->getMessage(), 'code' => $e->getStatusCode()]);
|
||||
// }
|
||||
// This is to check if the debug is true or false
|
||||
// if (config('app.debug') == false) {
|
||||
// // checking if the error is actually an error page or if its an system error page
|
||||
// if ($this->isHttpException($e) && $e->getStatusCode() == 404) {
|
||||
// return response()->view('errors.404', []);
|
||||
// } else {
|
||||
// // checking if the application is installed
|
||||
// if (\Config::get('database.install') == 1) {
|
||||
// // checking if the error log send to Ladybirdweb is enabled or not
|
||||
// if (\Config::get('app.ErrorLog') == '1') {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// return response()->view('errors.500', []);
|
||||
// }
|
||||
// }
|
||||
// returns non oops error message
|
||||
// return parent::render($request, $e);
|
||||
// checking if the error is related to http error i.e. page not found
|
||||
// if ($this->isHttpException($e)) {
|
||||
// // returns error for page not found
|
||||
// return $this->renderHttpException($e);
|
||||
// }
|
||||
// // checking if the config app sebug is enabled or not
|
||||
// if (config('app.debug')) {
|
||||
// // returns oops error page i.e. colour full error page
|
||||
// return $this->renderExceptionWithWhoops($e);
|
||||
// }
|
||||
//return parent::render($request, $e);
|
||||
// }
|
||||
|
||||
/**
|
||||
* function to generate oops error page.
|
||||
*
|
||||
* @param \Exception $e
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
// protected function renderExceptionWithWhoops(Exception $e) {
|
||||
// // new instance of whoops class to display customized error page
|
||||
// $whoops = new \Whoops\Run();
|
||||
// $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
|
||||
//
|
||||
// return new \Illuminate\Http\Response(
|
||||
// $whoops->handleException($e), $e->getStatusCode(), $e->getHeaders()
|
||||
// );
|
||||
// }
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
@@ -148,7 +71,6 @@ class Handler extends ExceptionHandler
|
||||
return $this->common($request, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to render 500 error page.
|
||||
*
|
||||
@@ -162,10 +84,9 @@ class Handler extends ExceptionHandler
|
||||
if (config('app.debug') == true) {
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
|
||||
return redirect()->route('error500', []);
|
||||
return response()->view('errors.500');
|
||||
//return redirect()->route('error500', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to render 404 error page.
|
||||
*
|
||||
@@ -176,13 +97,38 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function render404($request, $e)
|
||||
{
|
||||
|
||||
$seg = $request->segments();
|
||||
if (in_array('api', $seg)) {
|
||||
return response()->json(['status' => '404']);
|
||||
}
|
||||
if (config('app.debug') == true) {
|
||||
if($e->getStatusCode() == '404') {
|
||||
return redirect()->route('error404', []);
|
||||
}
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
return redirect()->route('error404', []);
|
||||
}
|
||||
/**
|
||||
* Function to render database connection failed
|
||||
*
|
||||
* @param type $request
|
||||
* @param type $e
|
||||
*
|
||||
* @return type mixed
|
||||
*/
|
||||
public function renderDB($request, $e)
|
||||
{
|
||||
$seg = $request->segments();
|
||||
if (in_array('api', $seg)) {
|
||||
return response()->json(['status' => '404']);
|
||||
}
|
||||
if (config('app.debug') == true) {
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
|
||||
return redirect()->route('error404', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common finction to render both types of codes.
|
||||
*
|
||||
@@ -198,10 +144,21 @@ class Handler extends ExceptionHandler
|
||||
return $this->render404($request, $e);
|
||||
case $e instanceof NotFoundHttpException:
|
||||
return $this->render404($request, $e);
|
||||
case $e instanceof PDOException:
|
||||
if(strpos('1045', $e->getMessage()) == true) {
|
||||
return $this->renderDB($request, $e);
|
||||
} else {
|
||||
return $this->render500($request, $e);
|
||||
}
|
||||
// case $e instanceof ErrorException:
|
||||
// if($e->getMessage() == 'Breadcrumb not found with name "" ') {
|
||||
// return $this->render404($request, $e);
|
||||
// } else {
|
||||
// return parent::render($request, $e);
|
||||
// }
|
||||
default:
|
||||
return $this->render500($request, $e);
|
||||
}
|
||||
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user