62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Core\Tenant\Exceptions;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Exception thrown when a referenced package does not exist.
|
||
|
|
*
|
||
|
|
* This exception is thrown during provisioning when the requested package
|
||
|
|
* code cannot be found in the packages table.
|
||
|
|
*
|
||
|
|
* @see EntitlementException Base exception class
|
||
|
|
*/
|
||
|
|
class PackageNotFoundException extends EntitlementException
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
string $message = 'The requested package was not found.',
|
||
|
|
public readonly ?string $packageCode = null,
|
||
|
|
int $code = 404,
|
||
|
|
?\Throwable $previous = null
|
||
|
|
) {
|
||
|
|
parent::__construct($message, featureCode: null, code: $code, previous: $previous);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create exception for a specific package code.
|
||
|
|
*/
|
||
|
|
public static function forCode(string $packageCode): self
|
||
|
|
{
|
||
|
|
return new self(
|
||
|
|
message: "Package '{$packageCode}' not found.",
|
||
|
|
packageCode: $packageCode,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the package code that was not found.
|
||
|
|
*/
|
||
|
|
public function getPackageCode(): ?string
|
||
|
|
{
|
||
|
|
return $this->packageCode;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Render the exception as an HTTP response.
|
||
|
|
*/
|
||
|
|
public function render($request)
|
||
|
|
{
|
||
|
|
if ($request->expectsJson()) {
|
||
|
|
return response()->json([
|
||
|
|
'message' => $this->getMessage(),
|
||
|
|
'error' => 'package_not_found',
|
||
|
|
'package_code' => $this->packageCode,
|
||
|
|
], $this->getCode());
|
||
|
|
}
|
||
|
|
|
||
|
|
return redirect()->back()
|
||
|
|
->with('error', $this->getMessage());
|
||
|
|
}
|
||
|
|
}
|