New error handler for API.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\DTO\ApiErrorMessage;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class ApiErrorException extends HttpException
|
||||
{
|
||||
|
||||
private ApiErrorMessage $apiErrorMsg;
|
||||
|
||||
public function __construct(ApiErrorMessage $apiErrorMsg, $detailsData = null, \Exception $previous = null, array $headers = array(), $code = 0)
|
||||
{
|
||||
$this->apiErrorMsg = $apiErrorMsg;
|
||||
|
||||
if (isset($detailsData)) {
|
||||
$this->apiErrorMsg->setDetails($detailsData);
|
||||
}
|
||||
|
||||
$statusCode = $apiErrorMsg->getStatusCode();
|
||||
$message = $apiErrorMsg->getTitle();
|
||||
|
||||
parent::__construct($statusCode, $message, $previous, $headers, $code);
|
||||
}
|
||||
|
||||
public function getApiErrorMsg(): ApiErrorMessage
|
||||
{
|
||||
return $this->apiErrorMsg;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user