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.
willaengine/app/Exceptions/Handler.php

72 lines
2.0 KiB

6 years ago
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
use WM\Core\Exceptions\HasRelationException;
4 years ago
use WM\Core\Exceptions\ValidationErrorException;
use WM\Core\Services\Responser;
use WM\WebBuilder\Exceptions\SiteBannedException;
6 years ago
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
6 years ago
* @return void
*/
public function report(Throwable $exception)
6 years ago
{
4 years ago
if (app()->bound('sentry') && $this->shouldReport($exception)) {
app('sentry')->captureException($exception);
}
6 years ago
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Throwable $exception
6 years ago
* @return \Illuminate\Http\Response
*/
public function render($request, Throwable $exception)
6 years ago
{
4 years ago
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);
}
4 years ago
}
6 years ago
return parent::render($request, $exception);
}
}