%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/hrsys/api/app/Exceptions/
Upload File :
Create Path :
Current File : /var/www/html/hrsys/api/app/Exceptions/Handler.php

<?php

namespace App\Exceptions;

use App\Http\Controllers\Api\ApiController;
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Validation\ValidationException;
use Spatie\Permission\Exceptions\UnauthorizedException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        AuthenticationException::class,
        AuthorizationException::class,
        ModelNotFoundException::class,
        TokenMismatchException::class,
        UnauthorizedException::class,
        ValidationException::class,
        ApiException::class,
    ];

    /**
     * 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
     * @throws Exception
     */
    public function report(Throwable $exception)
    {
        parent::report($exception);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param Request $request
     * @param Throwable $exception
     * @return \Symfony\Component\HttpFoundation\Response
     * @throws Throwable
     */
    public function render($request, Throwable $exception)
    {
        if ($exception instanceof UnauthorizedException) {
            return app(ApiController::class)->unauthorized([
                'message' => trans('auth.unauthorized'),
            ]);
        }
        if ($exception instanceof MethodNotAllowedHttpException) {
            return app(ApiController::class)->methodNotAllowed();
        }
        if ($exception instanceof NotFoundHttpException) {
            return app(ApiController::class)->notFound([
                'message' => 'Resource not found',
            ]);
        }
        if ($exception instanceof ModelNotFoundException) {
            $model = last(explode("\\", $exception->getModel()));

            return app(ApiController::class)->notFound([
                'message' => trans('exceptions.no_query_result_for_model', [
                    'model' => $model,
                ]),
            ]);
        }
        return parent::render($request, $exception);
    }

}

Zerion Mini Shell 1.0