���Root Mod By V1rus_Alfa
User / IP
:
216.73.217.78
Host / Server
:
195.214.235.115 / npln.ir
System
:
Linux damavand.pws-dns.net 5.14.0-503.35.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Apr 4 05:23:43 EDT 2025 x86_64
Command
|
Upload
|
Mass Deface
|
Create
:
/
home2
/
cutunixc
/
repositories
/
dasterang-api
/
modules
/
Shared
/
Services
/
Viewing: ExceptionHandler.php
<?php namespace Modules\Shared\Services; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Auth\AuthenticationException; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\QueryException; use Illuminate\Http\Request; use Illuminate\Validation\ValidationException; use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Throwable; /** * */ class ExceptionHandler { public function handle($exception) { return match (true) { $exception instanceof ValidationException => $this->handleValidationException($exception), $exception instanceof ModelNotFoundException => $this->handleModelNotFoundException($exception), $exception instanceof AuthenticationException => $this->handleAuthenticationException($exception), // Authorization exceptions (most specific first) $exception instanceof AuthorizationException => $this->handleAuthorizationException($exception), $exception instanceof AccessDeniedException => $this->handleAuthorizationException($exception), // Database exceptions $exception instanceof QueryException => $this->handleQueryException($exception), // HTTP exceptions (specific before generic) $exception instanceof NotFoundHttpException => $this->handleNotFoundHttpException($exception), $exception instanceof MethodNotAllowedHttpException => $this->handleMethodNotAllowedException($exception), $exception instanceof HttpException => $this->handleHttpException($exception), // Generic HTTP - goes last default => $this->handleGenericException($exception), }; } private function handleValidationException(ValidationException $exception) { return Responder::error(trans('container.the_given_data_is_invalid'), $exception->errors(), Response::HTTP_UNPROCESSABLE_ENTITY); } private function handleGenericException(Throwable $exception) { $statusCode = method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : Response::HTTP_INTERNAL_SERVER_ERROR; return Responder::error('An internal server error has occurred.', [ $exception->getMessage(), ...$exception->getTrace() ], $statusCode); } private function handleModelNotFoundException(ModelNotFoundException $exception) { $model = class_basename($exception->getModel()); return Responder::error("The requested {$model} was not found", 'Resource not found', Response::HTTP_NOT_FOUND); } private function handleAuthenticationException(AuthenticationException $exception) { return Responder::error('Authentication is required to access this resource', $exception->getMessage(), Response::HTTP_UNAUTHORIZED); } private function handleAuthorizationException(AuthorizationException|AccessDeniedException $exception) { return Responder::error('You do not have permission to access this resource', $exception->getMessage(), Response::HTTP_FORBIDDEN); } private function handleQueryException(QueryException $exception) { return Responder::error($exception->getMessage(), $exception->getTrace(), Response::HTTP_INTERNAL_SERVER_ERROR); } private function handleNotFoundHttpException(NotFoundHttpException $exception) { return Responder::error('The requested resource was not found: ' . $exception->getMessage(), $exception->getTrace(), Response::HTTP_NOT_FOUND); } private function handleMethodNotAllowedException(MethodNotAllowedHttpException $exception) { return Responder::error('The HTTP method is not allowed for this route: ' . $exception->getMessage(), $exception->getTrace(), Response::HTTP_METHOD_NOT_ALLOWED); } private function handleHttpException(HttpException $exception) { return Responder::error($exception->getMessage(), $exception->getTrace(), $exception->getStatusCode()); } }
Coded With 💗 by
0x6ick Mod By V1rus_Alfa