| 1 |
<?php |
| 2 |
|
| 3 |
namespace Templately\Modules\FullSiteImport\Concerns; |
| 4 |
|
| 5 |
use Exception; |
| 6 |
use Templately\Modules\FullSiteImport\Exception\FatalErrorException; |
| 7 |
use Templately\Modules\FullSiteImport\Exception\RetryableErrorException; |
| 8 |
use Templately\Modules\FullSiteImport\Exception\UnknownErrorException; |
| 9 |
use Templately\Utils\Helper; |
| 10 |
|
| 11 |
/** |
| 12 |
* Error-throw helpers for the Full Site Import pipeline. |
| 13 |
* |
| 14 |
* Extracted verbatim from FullSiteImport for readability. These are composed back |
| 15 |
* into FullSiteImport via `use`, so $this and method resolution are identical. |
| 16 |
*/ |
| 17 |
trait ThrowsErrors { |
| 18 |
/** |
| 19 |
* @throws Exception |
| 20 |
*/ |
| 21 |
private function throw($message, $code = 0) { |
| 22 |
if ($this->dev_mode) { |
| 23 |
Helper::log($message, 'fsi_error'); |
| 24 |
} |
| 25 |
throw new Exception($message); |
| 26 |
} |
| 27 |
/** |
| 28 |
* @throws Exception |
| 29 |
*/ |
| 30 |
private function throw_non_retryable($message, $code = 0) { |
| 31 |
if ($this->dev_mode) { |
| 32 |
Helper::log($message, 'fsi_error'); |
| 33 |
} |
| 34 |
throw new FatalErrorException($message); |
| 35 |
} |
| 36 |
/** |
| 37 |
* @throws Exception |
| 38 |
*/ |
| 39 |
private function throw_retryable($message, $code = 0) { |
| 40 |
if ($this->dev_mode) { |
| 41 |
Helper::log($message, 'fsi_error'); |
| 42 |
} |
| 43 |
throw new RetryableErrorException($message); |
| 44 |
} |
| 45 |
/** |
| 46 |
* @throws Exception |
| 47 |
*/ |
| 48 |
private function throw_unknown($message, $code = 0) { |
| 49 |
if ($this->dev_mode) { |
| 50 |
Helper::log($message, 'fsi_error'); |
| 51 |
} |
| 52 |
throw new UnknownErrorException($message); |
| 53 |
} |
| 54 |
} |
| 55 |
|