You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.0 KiB
72 lines
2.0 KiB
<?php
|
|
|
|
namespace App\Exceptions;
|
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
|
use Throwable;
|
|
use WM\Core\Exceptions\HasRelationException;
|
|
use WM\Core\Exceptions\ValidationErrorException;
|
|
use WM\Core\Services\Responser;
|
|
use WM\WebBuilder\Exceptions\SiteBannedException;
|
|
|
|
class Handler extends ExceptionHandler
|
|
{
|
|
/**
|
|
* A list of the exception types that are not reported.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $dontReport = [
|
|
//
|
|
];
|
|
|
|
/**
|
|
* A list of the inputs that are never flashed for validation exceptions.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $dontFlash = [
|
|
'password',
|
|
'password_confirmation',
|
|
];
|
|
|
|
/**
|
|
* Report or log an exception.
|
|
*
|
|
* @param \Throwable $exception
|
|
* @return void
|
|
*/
|
|
public function report(Throwable $exception)
|
|
{
|
|
if (app()->bound('sentry') && $this->shouldReport($exception)) {
|
|
app('sentry')->captureException($exception);
|
|
}
|
|
|
|
parent::report($exception);
|
|
}
|
|
|
|
/**
|
|
* Render an exception into an HTTP response.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Throwable $exception
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function render($request, Throwable $exception)
|
|
{
|
|
if ($exception instanceof ValidationErrorException) {
|
|
return response()->json(Responser::error($exception->getMessageBody(), $exception->getMessageInfo()), 422);
|
|
} elseif ($exception instanceof SiteBannedException) {
|
|
return response()->view('webBuilder::errors.template_disabled', ['error' => 'business banned']);
|
|
} elseif ($exception instanceof HasRelationException) {
|
|
return response()->json(Responser::error([$exception->getMessage()]), 422);
|
|
} elseif ($this->isHttpException($exception)) {
|
|
if ($exception->getStatusCode() == 404) {
|
|
return response()->view('webBuilder::errors.404', [], 404);
|
|
}
|
|
}
|
|
|
|
return parent::render($request, $exception);
|
|
}
|
|
}
|