PHP code example of kamranahmedse / laravel-faulty

1. Go to this page and download the library: Download kamranahmedse/laravel-faulty library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kamranahmedse / laravel-faulty example snippets



use KamranAhmed\Faulty\Handler as FaultyHandler;

class Handler extends FaultyHandler {
   // ...
}

use KamranAhmed\Faulty\Exceptions\[ProblemType]Exception;
[ProblemType]Exception($detail, $title = '', $instance = '', $type = '')

// Include the exception classes from the given namespace

throw new BadRequestException('Invalid request data');
throw new ConflictException('Same request is already pending');
throw new ForbiddenException('You are not allowed to perform this action');
throw new InternalErrorException('Exports directory isn\'t writable');
throw new NoContentException('Deletion request successfuly accepted');
throw new NotFoundException('Item not found');
throw new NotModifiedException('..');
throw new PaymentRequiredException('..');
throw new PreconditionFailedException('..');
throw new ProcessingException('..');
throw new RequestTimeoutException('..');
throw new RequestTooLongException('..');
throw new UnauthorizedException('..');
throw new UnprocessableEntityException('..');

use KamranAhmed\Faulty\Exceptions\HttpException;

throw new HttpException($title = '', $status = 500, $detail = '', $instance = '', $type = '');

$typeUrl = route('api.problem', ['type' => 'forbidden']);
$occurence = route('account.error', ['account_id' => 'A837332A', 'log_id' => 34]);

(new ForbiddenException("Your account doesn't have the balance of 50 USD"))
    ->setTitle('Balance too low)
    ->setType($problemRoute)
    ->setInstance($occurence)
    ->toss();

(new ForbiddenException("Your account doesn't have the balance of 50 USD"))
    ->setTitle('Balance too low)
    ->setAdditional([
        'current_balance' => 40,
        '