71 lines
1.4 KiB
PHP
71 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Exceptions\Api\V2;
|
|
|
|
use App\Enums\ApiError;
|
|
use Exception;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Throwable;
|
|
|
|
/**
|
|
* This would be thrown if any of the case
|
|
* referenced in \App\Enums\ApiError would
|
|
* occur within the crm
|
|
*
|
|
* On the client an ApiErrorException would
|
|
* also be throw with the ApiError corresponding to
|
|
* the situation
|
|
*/
|
|
class ApiErrorException extends Exception
|
|
{
|
|
|
|
/**
|
|
* Api Error
|
|
*
|
|
* @var \App\Enums\ApiError
|
|
*/
|
|
protected $error;
|
|
|
|
/** @var string */
|
|
protected $message;
|
|
|
|
/** @var int */
|
|
protected $httpCode;
|
|
|
|
public function __construct(ApiError $error, int $httpCode = 400, string $message = '', Throwable $previous = null)
|
|
{
|
|
$this->error = $error;
|
|
$this->message = $message;
|
|
$this->httpCode = $httpCode;
|
|
parent::__construct(
|
|
strlen($this->message) ? $this->message : $error->label,
|
|
$error->value,
|
|
$previous
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the Api Error
|
|
*
|
|
* @return ApiError
|
|
*/
|
|
public function getApiError(): ApiError
|
|
{
|
|
return $this->error;
|
|
}
|
|
|
|
/**
|
|
* Get the http code
|
|
*
|
|
* @return int
|
|
*/
|
|
public function getStatusCode(): int
|
|
{
|
|
return $this->httpCode;
|
|
}
|
|
|
|
public function report()
|
|
{
|
|
Log::debug(sprintf('CRM API: %s', $this->getMessage()));
|
|
}
|
|
}
|