| 1 |
<?php |
| 2 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 3 |
|
| 4 |
namespace Yoast\WP\SEO\MyYoast_Client\Application\Exceptions; |
| 5 |
|
| 6 |
use RuntimeException; |
| 7 |
use Throwable; |
| 8 |
|
| 9 |
/** |
| 10 |
* Exception thrown when the authorization flow cannot be started. |
| 11 |
* |
| 12 |
* Wraps underlying failures (registration, discovery, invalid parameters) |
| 13 |
* that prevent building the authorization URL. |
| 14 |
*/ |
| 15 |
class Authorization_Flow_Exception extends RuntimeException { |
| 16 |
|
| 17 |
/** |
| 18 |
* The error code identifying the failure reason. |
| 19 |
* |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
private $error_code; |
| 23 |
|
| 24 |
/** |
| 25 |
* Authorization_Flow_Exception constructor. |
| 26 |
* |
| 27 |
* @param string $error_code The error code. |
| 28 |
* @param string $error_description A human-readable description. |
| 29 |
* @param int $code The exception code. |
| 30 |
* @param Throwable|null $previous The previous exception. |
| 31 |
*/ |
| 32 |
public function __construct( string $error_code, string $error_description = '', int $code = 0, ?Throwable $previous = null ) { |
| 33 |
$this->error_code = $error_code; |
| 34 |
|
| 35 |
$message = $error_code; |
| 36 |
if ( $error_description !== '' ) { |
| 37 |
$message .= ': ' . $error_description; |
| 38 |
} |
| 39 |
|
| 40 |
parent::__construct( $message, $code, $previous ); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Returns the error code. |
| 45 |
* |
| 46 |
* @return string |
| 47 |
*/ |
| 48 |
public function get_error_code(): string { |
| 49 |
return $this->error_code; |
| 50 |
} |
| 51 |
} |
| 52 |
|