Lae/app/Exceptions/Handler.php

66 lines
1.6 KiB
PHP
Raw Normal View History

2022-08-12 07:56:56 +00:00
<?php
namespace App\Exceptions;
2022-09-08 16:12:02 +00:00
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Validation\ValidationException;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\HttpException;
2022-08-12 07:56:56 +00:00
use Throwable;
class Handler extends ExceptionHandler
{
/**
2022-09-08 16:12:02 +00:00
* A list of the exception types that should not be reported.
2022-08-12 07:56:56 +00:00
*
2022-09-08 16:12:02 +00:00
* @var array
2022-08-12 07:56:56 +00:00
*/
protected $dontReport = [
2022-09-08 16:12:02 +00:00
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
ValidationException::class,
2022-08-12 07:56:56 +00:00
];
/**
2022-09-08 16:12:02 +00:00
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
2022-08-12 07:56:56 +00:00
*
2022-09-08 16:12:02 +00:00
* @param \Throwable $exception
* @return void
*
* @throws \Exception
2022-08-12 07:56:56 +00:00
*/
2022-09-08 16:12:02 +00:00
public function report(Throwable $exception)
{
parent::report($exception);
}
2022-08-12 07:56:56 +00:00
/**
2022-09-08 16:12:02 +00:00
* Render an exception into an HTTP response.
2022-08-12 07:56:56 +00:00
*
2022-09-08 16:12:02 +00:00
* @param \Illuminate\Http\Request $request
* @param \Throwable $exception
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
*
* @throws \Throwable
2022-08-12 07:56:56 +00:00
*/
2022-09-08 16:12:02 +00:00
public function render($request, Throwable $exception)
2022-08-12 07:56:56 +00:00
{
2022-09-08 17:32:42 +00:00
$rendered = parent::render($request, $exception);
return response()->json(
[
'error' => [
'code' => $rendered->getStatusCode(),
'message' => $exception->getMessage(),
]
],
$rendered->getStatusCode()
);
2022-08-12 07:56:56 +00:00
}
}