Engine
2 days ago
Integrations
2 days ago
Validator
11 months ago
class-bootstrap.php
3 months ago
class-container.php
9 months ago
class-email-css-inliner.php
9 months ago
class-email-editor-container.php
5 months ago
class-package.php
11 months ago
exceptions.php
11 months ago
index.php
11 months ago
exceptions.php
59 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | // phpcs:ignoreFile PSR1.Classes.ClassDeclaration |
| 3 | namespace Automattic\WooCommerce\EmailEditor; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | interface HttpAwareException { |
| 6 | public function getHttpStatusCode(): int; |
| 7 | } |
| 8 | abstract class Exception extends \Exception { |
| 9 | private $errors = []; |
| 10 | final public function __construct(string $message = '', int $code = 0, ?\Throwable $previous = null) { |
| 11 | parent::__construct($message, $code, $previous); |
| 12 | } |
| 13 | public static function create(?\Throwable $previous = null) { |
| 14 | return new static('', 0, $previous); |
| 15 | } |
| 16 | public function withMessage(string $message) { |
| 17 | $this->message = $message; |
| 18 | return $this; |
| 19 | } |
| 20 | public function withCode(int $code) { |
| 21 | $this->code = $code; |
| 22 | return $this; |
| 23 | } |
| 24 | public function withErrors(array $errors) { |
| 25 | $this->errors = $errors; |
| 26 | return $this; |
| 27 | } |
| 28 | public function withError(string $id, string $error) { |
| 29 | $this->errors[$id] = $error; |
| 30 | return $this; |
| 31 | } |
| 32 | public function getErrors(): array { |
| 33 | return $this->errors; |
| 34 | } |
| 35 | } |
| 36 | class RuntimeException extends Exception {} |
| 37 | class UnexpectedValueException extends RuntimeException implements HttpAwareException { |
| 38 | public function getHttpStatusCode(): int { |
| 39 | return 400; |
| 40 | } |
| 41 | } |
| 42 | class AccessDeniedException extends UnexpectedValueException implements HttpAwareException { |
| 43 | public function getHttpStatusCode(): int { |
| 44 | return 403; |
| 45 | } |
| 46 | } |
| 47 | class NotFoundException extends UnexpectedValueException implements HttpAwareException { |
| 48 | public function getHttpStatusCode(): int { |
| 49 | return 404; |
| 50 | } |
| 51 | } |
| 52 | class ConflictException extends UnexpectedValueException implements HttpAwareException { |
| 53 | public function getHttpStatusCode(): int { |
| 54 | return 409; |
| 55 | } |
| 56 | } |
| 57 | class InvalidStateException extends RuntimeException {} |
| 58 | class NewsletterProcessingException extends Exception {} |
| 59 |