30 lines
783 B
PHP
30 lines
783 B
PHP
<?php
|
|
|
|
namespace App\Services\InsForge;
|
|
|
|
use RuntimeException;
|
|
|
|
class InsForgeException extends RuntimeException
|
|
{
|
|
public function __construct(
|
|
public readonly ?string $errorCode,
|
|
public readonly int $statusCode,
|
|
string $message,
|
|
) {
|
|
parent::__construct($message, $statusCode);
|
|
}
|
|
|
|
public static function fromResponse(int $statusCode, array|string $body): self
|
|
{
|
|
if (is_array($body)) {
|
|
return new self(
|
|
$body['error'] ?? null,
|
|
$body['statusCode'] ?? $statusCode,
|
|
$body['message'] ?? 'InsForge request failed',
|
|
);
|
|
}
|
|
|
|
return new self(null, $statusCode, $body !== '' ? $body : "InsForge request failed with status {$statusCode}");
|
|
}
|
|
}
|