54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Core\Tenant\Exceptions;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Exception thrown when a referenced feature does not exist.
|
||
|
|
*
|
||
|
|
* This exception is thrown when an entitlement check references a feature
|
||
|
|
* code that is not defined in the features table.
|
||
|
|
*
|
||
|
|
* @see EntitlementException Base exception class
|
||
|
|
*/
|
||
|
|
class FeatureNotFoundException extends EntitlementException
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
string $message = 'The requested feature was not found.',
|
||
|
|
?string $featureCode = null,
|
||
|
|
int $code = 404,
|
||
|
|
?\Throwable $previous = null
|
||
|
|
) {
|
||
|
|
parent::__construct($message, $featureCode, $code, $previous);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create exception for a specific feature code.
|
||
|
|
*/
|
||
|
|
public static function forCode(string $featureCode): self
|
||
|
|
{
|
||
|
|
return new self(
|
||
|
|
message: "Feature '{$featureCode}' does not exist.",
|
||
|
|
featureCode: $featureCode,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Render the exception as an HTTP response.
|
||
|
|
*/
|
||
|
|
public function render($request)
|
||
|
|
{
|
||
|
|
if ($request->expectsJson()) {
|
||
|
|
return response()->json([
|
||
|
|
'message' => $this->getMessage(),
|
||
|
|
'error' => 'feature_not_found',
|
||
|
|
'feature_code' => $this->featureCode,
|
||
|
|
], $this->getCode());
|
||
|
|
}
|
||
|
|
|
||
|
|
return redirect()->back()
|
||
|
|
->with('error', $this->getMessage());
|
||
|
|
}
|
||
|
|
}
|