%PDF- %PDF-
Mini Shell

Mini Shell

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

<?php

namespace App\Exceptions;

use App\Http\Controllers\Api\ApiController;
use App\Jobs\SendExceptionToSlack;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
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 \Illuminate\Http\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' => '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' => 'No query results for model ' . $model,
            ]);
        }
        if ($exception instanceof WebhookException) {
            dispatch(new SendExceptionToSlack($exception->getMessage()));
            return response()->json([
                'message' => $exception->getMessage(),
            ], $exception->getCode());
        }
        return parent::render($request, $exception);
    }
}

Zerion Mini Shell 1.0