PHP code example of boltics / http-exception

1. Go to this page and download the library: Download boltics/http-exception 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/ */

    

boltics / http-exception example snippets


use Boltics\HttpException\Exception;
use Symfony\Component\HttpFoundation\Response;

$errorInfo = [
    'message' => 'Hola',
    'errorCode' => 1234,
    'httpCode' => Response::HTTP_BAD_REQUEST
];

throw new Exception($errorInfo);

// For Laravel Response
// You can use one exception to manage both error code and http code

class CustomizedException extends Exception
{
    const FIRST_ERROR = [
        'message' => 'Hola',
        'errorCode' => 1234,
        'httpCode' => Response::HTTP_BAD_REQUEST
    ];
}

try {
    // do something
    throw new CustomizedException(CustomizedException::FIRST_ERROR);
} catch (CustomizedException $e) {
    return $reponse()->json($data, $e->getHttpCode())
}