diff --git a/src/Codeception/Module/Percy.php b/src/Codeception/Module/Percy.php index cd68498..1bc9298 100644 --- a/src/Codeception/Module/Percy.php +++ b/src/Codeception/Module/Percy.php @@ -16,6 +16,11 @@ */ class Percy extends Module { + /** + * Module namespace, for use with exceptions + */ + const MODULE_NAMESPACE = 'Percy'; + /** * @var array */ @@ -62,6 +67,7 @@ public function _initialize() $this->percyAgentJs = Client::fromUrl($this->buildUrl($this->_getConfig('agentJsPath')))->get(); } catch (Exception $exception) { throw new SetupException( + self::MODULE_NAMESPACE, sprintf( 'Cannot contact the Percy agent endpoint. Has Codeception been launched with `npx percy exec`? %s', $exception->getMessage() @@ -139,6 +145,7 @@ private function getSnapshotConfig() : array } throw new ConfigException( + self::MODULE_NAMESPACE, sprintf('The following key is not allowed to be set through config: %s', $blacklistKey) ); } diff --git a/src/Codeception/Module/Percy/Exception/ClientException.php b/src/Codeception/Module/Percy/Exception/ClientException.php index eb47dec..e588ab1 100644 --- a/src/Codeception/Module/Percy/Exception/ClientException.php +++ b/src/Codeception/Module/Percy/Exception/ClientException.php @@ -2,14 +2,14 @@ namespace Codeception\Module\Percy\Exception; -use Exception; +use Codeception\Exception\ModuleException; /** * Class ClientException * * @package Codeception\Module\Percy\Exception */ -final class ClientException extends Exception +final class ClientException extends ModuleException { // } diff --git a/src/Codeception/Module/Percy/Exception/ConfigException.php b/src/Codeception/Module/Percy/Exception/ConfigException.php index 1b307d7..a5aecda 100644 --- a/src/Codeception/Module/Percy/Exception/ConfigException.php +++ b/src/Codeception/Module/Percy/Exception/ConfigException.php @@ -2,14 +2,14 @@ namespace Codeception\Module\Percy\Exception; -use Exception; +use Codeception\Exception\ModuleException; /** * Class ConfigException * * @package Codeception\Module\Percy\Exception */ -final class ConfigException extends Exception +final class ConfigException extends ModuleException { // } diff --git a/src/Codeception/Module/Percy/Exception/SetupException.php b/src/Codeception/Module/Percy/Exception/SetupException.php index 4d58186..0edf3cd 100644 --- a/src/Codeception/Module/Percy/Exception/SetupException.php +++ b/src/Codeception/Module/Percy/Exception/SetupException.php @@ -2,14 +2,14 @@ namespace Codeception\Module\Percy\Exception; -use Exception; +use Codeception\Exception\ModuleException; /** * Class SetupException * * @package Codeception\Module\Percy\Exception */ -final class SetupException extends Exception +final class SetupException extends ModuleException { // } diff --git a/src/Codeception/Module/Percy/Exchange/CurlAdapter.php b/src/Codeception/Module/Percy/Exchange/CurlAdapter.php index 5078b1c..4306323 100644 --- a/src/Codeception/Module/Percy/Exchange/CurlAdapter.php +++ b/src/Codeception/Module/Percy/Exchange/CurlAdapter.php @@ -3,6 +3,7 @@ namespace Codeception\Module\Percy\Exchange; use Codeception\Module\Percy\Exception\ClientException; +use Codeception\Module\Percy; /** * Class CurlAdapter @@ -62,7 +63,7 @@ public function execute() : string { $output = curl_exec($this->resource); if (curl_errno($this->resource)) { - throw new ClientException(curl_error($this->resource)); + throw new ClientException(Percy::MODULE_NAMESPACE, curl_error($this->resource)); } curl_close($this->resource);