This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add meaningful exceptions (#46)
- Loading branch information
Showing
15 changed files
with
295 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/Bridge/Symfony/Bundle/Exception/CouldNotCreatePidFileException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Bridge\Symfony\Bundle\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class CouldNotCreatePidFileException extends \RuntimeException | ||
{ | ||
public static function forPath(string $pidFile): self | ||
{ | ||
throw new self(\sprintf('Could not create pid file "%s".', $pidFile)); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Bridge/Symfony/Bundle/Exception/PidFileNotAccessibleException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Bridge\Symfony\Bundle\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class PidFileNotAccessibleException extends \RuntimeException | ||
{ | ||
public static function forFile(string $pidFile): self | ||
{ | ||
throw new self(\sprintf('Could not access pid file "%s".', $pidFile)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Client\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ClientConnectionErrorException extends \RuntimeException | ||
{ | ||
public static function failed(int $errorCode): self | ||
{ | ||
return new self('Connection Failed', $errorCode); | ||
} | ||
|
||
public static function requestTimeout(int $errorCode): self | ||
{ | ||
return new self('Request Timeout', $errorCode); | ||
} | ||
|
||
public static function serverReset(int $errorCode): self | ||
{ | ||
return new self('Server Reset', $errorCode); | ||
} | ||
|
||
public static function unknown(int $errorCode): self | ||
{ | ||
return new self('Unknown', $errorCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Client\Exception; | ||
|
||
use K911\Swoole\Client\Http; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class InvalidContentTypeException extends \InvalidArgumentException | ||
{ | ||
private const SUPPORTED_CONTENT_TYPES = [ | ||
Http::CONTENT_TYPE_APPLICATION_JSON, | ||
Http::CONTENT_TYPE_TEXT_PLAIN, | ||
]; | ||
|
||
public static function forContentType(string $contentType): self | ||
{ | ||
return new self(\sprintf('Content-Type "%s" is not supported. Only "%s" are supported.', $contentType, \implode(', ', self::SUPPORTED_CONTENT_TYPES))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Client\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class InvalidHttpMethodException extends \InvalidArgumentException | ||
{ | ||
public static function forMethod(string $method, array $allowed): self | ||
{ | ||
return new self(\sprintf('Content-Type "%s" is not supported. Only "%s" are supported.', $method, \implode(', ', $allowed))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Client\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class MissingContentTypeException extends \InvalidArgumentException | ||
{ | ||
public static function create(): self | ||
{ | ||
return new self(\sprintf('Server response did not contain Content-Type.')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class AlreadyAttachedException extends \RuntimeException | ||
{ | ||
public static function create(): self | ||
{ | ||
return new self('Swoole HTTP Server has been already attached. Cannot attach server or listeners multiple times.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class InvalidServerPortException extends \InvalidArgumentException | ||
{ | ||
public static function with(int $port, int $expectedPort): self | ||
{ | ||
return new self(\sprintf('Attached Swoole HTTP Server has different port (%s), than expected (%s).', $port, $expectedPort)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class NoServerAttachedException extends \RuntimeException | ||
{ | ||
public static function create(): self | ||
{ | ||
return new self('Swoole HTTP Server has not been setup yet. Please use attach method.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class NotRunningException extends \RuntimeException | ||
{ | ||
public static function create(): self | ||
{ | ||
return new self('Swoole HTTP Server has not been running.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class PortUnavailableException extends \InvalidArgumentException | ||
{ | ||
public static function fortPort(int $port): self | ||
{ | ||
return new self(\sprintf('Cannot attach listener on port (%s). It is already registered.', $port)); | ||
} | ||
} |
Oops, something went wrong.